8643 fix sentry error (#8644)
- fixes missing data in event payload when adding a new workspaceMember - add strong typing to database event emitters
This commit is contained in:
@ -0,0 +1,13 @@
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { CustomEventName } from 'src/engine/workspace-event-emitter/types/custom-event-name.type';
|
||||
|
||||
export function OnCustomBatchEvent(event: CustomEventName): MethodDecorator {
|
||||
return (
|
||||
target: object,
|
||||
propertyKey: string,
|
||||
descriptor: PropertyDescriptor,
|
||||
) => {
|
||||
OnEvent(event)(target, propertyKey, descriptor);
|
||||
};
|
||||
}
|
||||
@ -2,7 +2,7 @@ import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
export function OnDatabaseEvent(
|
||||
export function OnDatabaseBatchEvent(
|
||||
object: string,
|
||||
action: DatabaseEventAction,
|
||||
): MethodDecorator {
|
||||
@ -17,9 +17,10 @@ export class ApiEventEmitterService {
|
||||
authContext: AuthContext,
|
||||
objectMetadataItem: ObjectMetadataInterface,
|
||||
): void {
|
||||
this.workspaceEventEmitter.emit(
|
||||
`${objectMetadataItem.nameSingular}.${DatabaseEventAction.CREATED}`,
|
||||
records.map((record) => ({
|
||||
this.workspaceEventEmitter.emitDatabaseBatchEvent({
|
||||
objectMetadataNameSingular: objectMetadataItem.nameSingular,
|
||||
action: DatabaseEventAction.CREATED,
|
||||
events: records.map((record) => ({
|
||||
userId: authContext.user?.id,
|
||||
recordId: record.id,
|
||||
objectMetadata: objectMetadataItem,
|
||||
@ -28,8 +29,8 @@ export class ApiEventEmitterService {
|
||||
after: this.removeGraphQLAndNestedProperties(record),
|
||||
},
|
||||
})),
|
||||
authContext.workspace.id,
|
||||
);
|
||||
workspaceId: authContext.workspace.id,
|
||||
});
|
||||
}
|
||||
|
||||
public emitUpdateEvents<T extends ObjectRecord>(
|
||||
@ -47,9 +48,10 @@ export class ApiEventEmitterService {
|
||||
{},
|
||||
);
|
||||
|
||||
this.workspaceEventEmitter.emit(
|
||||
`${objectMetadataItem.nameSingular}.${DatabaseEventAction.UPDATED}`,
|
||||
records.map((record) => {
|
||||
this.workspaceEventEmitter.emitDatabaseBatchEvent({
|
||||
objectMetadataNameSingular: objectMetadataItem.nameSingular,
|
||||
action: DatabaseEventAction.UPDATED,
|
||||
events: records.map((record) => {
|
||||
const before = this.removeGraphQLAndNestedProperties(
|
||||
mappedExistingRecords[record.id],
|
||||
);
|
||||
@ -73,8 +75,8 @@ export class ApiEventEmitterService {
|
||||
},
|
||||
};
|
||||
}),
|
||||
authContext.workspace.id,
|
||||
);
|
||||
workspaceId: authContext.workspace.id,
|
||||
});
|
||||
}
|
||||
|
||||
public emitDeletedEvents<T extends ObjectRecord>(
|
||||
@ -82,9 +84,10 @@ export class ApiEventEmitterService {
|
||||
authContext: AuthContext,
|
||||
objectMetadataItem: ObjectMetadataInterface,
|
||||
): void {
|
||||
this.workspaceEventEmitter.emit(
|
||||
`${objectMetadataItem.nameSingular}.${DatabaseEventAction.DELETED}`,
|
||||
records.map((record) => {
|
||||
this.workspaceEventEmitter.emitDatabaseBatchEvent({
|
||||
objectMetadataNameSingular: objectMetadataItem.nameSingular,
|
||||
action: DatabaseEventAction.DELETED,
|
||||
events: records.map((record) => {
|
||||
return {
|
||||
userId: authContext.user?.id,
|
||||
recordId: record.id,
|
||||
@ -95,8 +98,8 @@ export class ApiEventEmitterService {
|
||||
},
|
||||
};
|
||||
}),
|
||||
authContext.workspace.id,
|
||||
);
|
||||
workspaceId: authContext.workspace.id,
|
||||
});
|
||||
}
|
||||
|
||||
public emitDestroyEvents<T extends ObjectRecord>(
|
||||
@ -104,9 +107,10 @@ export class ApiEventEmitterService {
|
||||
authContext: AuthContext,
|
||||
objectMetadataItem: ObjectMetadataInterface,
|
||||
): void {
|
||||
this.workspaceEventEmitter.emit(
|
||||
`${objectMetadataItem.nameSingular}.${DatabaseEventAction.DESTROYED}`,
|
||||
records.map((record) => {
|
||||
this.workspaceEventEmitter.emitDatabaseBatchEvent({
|
||||
objectMetadataNameSingular: objectMetadataItem.nameSingular,
|
||||
action: DatabaseEventAction.DESTROYED,
|
||||
events: records.map((record) => {
|
||||
return {
|
||||
userId: authContext.user?.id,
|
||||
recordId: record.id,
|
||||
@ -117,8 +121,8 @@ export class ApiEventEmitterService {
|
||||
},
|
||||
};
|
||||
}),
|
||||
authContext.workspace.id,
|
||||
);
|
||||
workspaceId: authContext.workspace.id,
|
||||
});
|
||||
}
|
||||
|
||||
private removeGraphQLAndNestedProperties<T extends ObjectRecord>(record: T) {
|
||||
|
||||
Reference in New Issue
Block a user