6071 return only updated fields of records in zapier update trigger (#8193)
- move webhook triggers into `entity-events-to-db.listener.ts` - refactor event management - add a `@OnDatabaseEvent` decorator to manage database events - add updatedFields in updated events - update openApi webhooks docs - update zapier integration
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
@ -17,6 +16,8 @@ import {
|
||||
BlocklistReimportCalendarEventsJob,
|
||||
BlocklistReimportCalendarEventsJobData,
|
||||
} from 'src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class CalendarBlocklistListener {
|
||||
@ -25,7 +26,7 @@ export class CalendarBlocklistListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('blocklist.created')
|
||||
@OnDatabaseEvent('blocklist', DatabaseEventAction.CREATED)
|
||||
async handleCreatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordCreateEvent<BlocklistWorkspaceEntity>
|
||||
@ -37,7 +38,7 @@ export class CalendarBlocklistListener {
|
||||
);
|
||||
}
|
||||
|
||||
@OnEvent('blocklist.deleted')
|
||||
@OnDatabaseEvent('blocklist', DatabaseEventAction.DELETED)
|
||||
async handleDeletedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordDeleteEvent<BlocklistWorkspaceEntity>
|
||||
@ -49,7 +50,7 @@ export class CalendarBlocklistListener {
|
||||
);
|
||||
}
|
||||
|
||||
@OnEvent('blocklist.updated')
|
||||
@OnDatabaseEvent('blocklist', DatabaseEventAction.UPDATED)
|
||||
async handleUpdatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordUpdateEvent<BlocklistWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
@ -11,6 +10,8 @@ import {
|
||||
DeleteConnectedAccountAssociatedCalendarDataJobData,
|
||||
} from 'src/modules/calendar/calendar-event-cleaner/jobs/delete-connected-account-associated-calendar-data.job';
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class CalendarEventCleanerConnectedAccountListener {
|
||||
@ -19,7 +20,7 @@ export class CalendarEventCleanerConnectedAccountListener {
|
||||
private readonly calendarQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('connectedAccount.destroyed')
|
||||
@OnDatabaseEvent('connectedAccount', DatabaseEventAction.DESTROYED)
|
||||
async handleDestroyedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordDeleteEvent<ConnectedAccountWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event';
|
||||
@ -17,6 +16,8 @@ import {
|
||||
CalendarEventParticipantUnmatchParticipantJobData,
|
||||
} from 'src/modules/calendar/calendar-event-participant-manager/jobs/calendar-event-participant-unmatch-participant.job';
|
||||
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class CalendarEventParticipantPersonListener {
|
||||
@ -25,7 +26,7 @@ export class CalendarEventParticipantPersonListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('person.created')
|
||||
@OnDatabaseEvent('person', DatabaseEventAction.CREATED)
|
||||
async handleCreatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordCreateEvent<PersonWorkspaceEntity>
|
||||
@ -48,7 +49,7 @@ export class CalendarEventParticipantPersonListener {
|
||||
}
|
||||
}
|
||||
|
||||
@OnEvent('person.updated')
|
||||
@OnDatabaseEvent('person', DatabaseEventAction.UPDATED)
|
||||
async handleUpdatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordUpdateEvent<PersonWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event';
|
||||
@ -17,6 +16,8 @@ import {
|
||||
CalendarEventParticipantUnmatchParticipantJobData,
|
||||
} from 'src/modules/calendar/calendar-event-participant-manager/jobs/calendar-event-participant-unmatch-participant.job';
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class CalendarEventParticipantWorkspaceMemberListener {
|
||||
@ -25,7 +26,7 @@ export class CalendarEventParticipantWorkspaceMemberListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('workspaceMember.created')
|
||||
@OnDatabaseEvent('workspaceMember', DatabaseEventAction.CREATED)
|
||||
async handleCreatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordCreateEvent<WorkspaceMemberWorkspaceEntity>
|
||||
@ -47,7 +48,7 @@ export class CalendarEventParticipantWorkspaceMemberListener {
|
||||
}
|
||||
}
|
||||
|
||||
@OnEvent('workspaceMember.updated')
|
||||
@OnDatabaseEvent('workspaceMember', DatabaseEventAction.UPDATED)
|
||||
async handleUpdatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordUpdateEvent<WorkspaceMemberWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
@ -7,6 +6,8 @@ import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/workspac
|
||||
import { AccountsToReconnectService } from 'src/modules/connected-account/services/accounts-to-reconnect.service';
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class ConnectedAccountListener {
|
||||
@ -15,7 +16,7 @@ export class ConnectedAccountListener {
|
||||
private readonly accountsToReconnectService: AccountsToReconnectService,
|
||||
) {}
|
||||
|
||||
@OnEvent('connectedAccount.destroyed')
|
||||
@OnDatabaseEvent('connectedAccount', DatabaseEventAction.DESTROYED)
|
||||
async handleDestroyedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordDeleteEvent<ConnectedAccountWorkspaceEntity>
|
||||
|
||||
@ -7,6 +7,7 @@ import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/t
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { WorkspaceEventEmitter } from 'src/engine/workspace-event-emitter/workspace-event-emitter';
|
||||
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@WorkspaceQueryHook(`connectedAccount.destroyOne`)
|
||||
export class ConnectedAccountDeleteOnePreQueryHook
|
||||
@ -34,7 +35,7 @@ export class ConnectedAccountDeleteOnePreQueryHook
|
||||
});
|
||||
|
||||
this.workspaceEventEmitter.emit(
|
||||
'messageChannel.destroyed',
|
||||
`messageChannel.${DatabaseEventAction.DESTROYED}`,
|
||||
messageChannels.map(
|
||||
(messageChannel) =>
|
||||
({
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event';
|
||||
import { objectRecordChangedProperties } from 'src/engine/core-modules/event-emitter/utils/object-record-changed-properties.util';
|
||||
@ -12,6 +11,8 @@ import {
|
||||
CalendarCreateCompanyAndContactAfterSyncJobData,
|
||||
} from 'src/modules/calendar/calendar-event-participant-manager/jobs/calendar-create-company-and-contact-after-sync.job';
|
||||
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class AutoCompaniesAndContactsCreationCalendarChannelListener {
|
||||
@ -20,7 +21,7 @@ export class AutoCompaniesAndContactsCreationCalendarChannelListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('calendarChannel.updated')
|
||||
@OnDatabaseEvent('calendarChannel', DatabaseEventAction.UPDATED)
|
||||
async handleUpdatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordUpdateEvent<MessageChannelWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event';
|
||||
import { objectRecordChangedProperties } from 'src/engine/core-modules/event-emitter/utils/object-record-changed-properties.util';
|
||||
@ -12,6 +11,8 @@ import {
|
||||
MessagingCreateCompanyAndContactAfterSyncJob,
|
||||
MessagingCreateCompanyAndContactAfterSyncJobData,
|
||||
} from 'src/modules/messaging/message-participant-manager/jobs/messaging-create-company-and-contact-after-sync.job';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class AutoCompaniesAndContactsCreationMessageChannelListener {
|
||||
@ -20,7 +21,7 @@ export class AutoCompaniesAndContactsCreationMessageChannelListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('messageChannel.updated')
|
||||
@OnDatabaseEvent('messageChannel', DatabaseEventAction.UPDATED)
|
||||
async handleUpdatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordUpdateEvent<MessageChannelWorkspaceEntity>
|
||||
|
||||
@ -25,6 +25,7 @@ import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/perso
|
||||
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository';
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
import { isWorkEmail } from 'src/utils/is-work-email';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class CreateCompanyAndContactService {
|
||||
@ -195,7 +196,7 @@ export class CreateCompanyAndContactService {
|
||||
);
|
||||
|
||||
this.workspaceEventEmitter.emit(
|
||||
'person.created',
|
||||
`person.${DatabaseEventAction.CREATED}`,
|
||||
createdPeople.map(
|
||||
(createdPerson) =>
|
||||
({
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable, Scope } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
@ -17,6 +16,8 @@ import {
|
||||
BlocklistReimportMessagesJob,
|
||||
BlocklistReimportMessagesJobData,
|
||||
} from 'src/modules/messaging/blocklist-manager/jobs/messaging-blocklist-reimport-messages.job';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable({ scope: Scope.REQUEST })
|
||||
export class MessagingBlocklistListener {
|
||||
@ -25,7 +26,7 @@ export class MessagingBlocklistListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('blocklist.created')
|
||||
@OnDatabaseEvent('blocklist', DatabaseEventAction.CREATED)
|
||||
async handleCreatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordCreateEvent<BlocklistWorkspaceEntity>
|
||||
@ -37,7 +38,7 @@ export class MessagingBlocklistListener {
|
||||
);
|
||||
}
|
||||
|
||||
@OnEvent('blocklist.deleted')
|
||||
@OnDatabaseEvent('blocklist', DatabaseEventAction.CREATED)
|
||||
async handleDeletedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordDeleteEvent<BlocklistWorkspaceEntity>
|
||||
@ -49,7 +50,7 @@ export class MessagingBlocklistListener {
|
||||
);
|
||||
}
|
||||
|
||||
@OnEvent('blocklist.updated')
|
||||
@OnDatabaseEvent('blocklist', DatabaseEventAction.UPDATED)
|
||||
async handleUpdatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordUpdateEvent<BlocklistWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
@ -11,6 +10,8 @@ import {
|
||||
MessagingConnectedAccountDeletionCleanupJob,
|
||||
MessagingConnectedAccountDeletionCleanupJobData,
|
||||
} from 'src/modules/messaging/message-cleaner/jobs/messaging-connected-account-deletion-cleanup.job';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class MessagingMessageCleanerConnectedAccountListener {
|
||||
@ -19,7 +20,7 @@ export class MessagingMessageCleanerConnectedAccountListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('connectedAccount.destroyed')
|
||||
@OnDatabaseEvent('connectedAccount', DatabaseEventAction.DESTROYED)
|
||||
async handleDestroyedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordDeleteEvent<ConnectedAccountWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
@ -11,6 +10,8 @@ import {
|
||||
MessagingCleanCacheJob,
|
||||
MessagingCleanCacheJobData,
|
||||
} from 'src/modules/messaging/message-import-manager/jobs/messaging-clean-cache';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class MessagingMessageImportManagerMessageChannelListener {
|
||||
@ -19,7 +20,7 @@ export class MessagingMessageImportManagerMessageChannelListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('messageChannel.destroyed')
|
||||
@OnDatabaseEvent('messageChannel', DatabaseEventAction.DESTROYED)
|
||||
async handleDestroyedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordDeleteEvent<MessageChannelWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event';
|
||||
@ -17,6 +16,8 @@ import {
|
||||
MessageParticipantUnmatchParticipantJobData,
|
||||
} from 'src/modules/messaging/message-participant-manager/jobs/message-participant-unmatch-participant.job';
|
||||
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class MessageParticipantPersonListener {
|
||||
@ -25,7 +26,7 @@ export class MessageParticipantPersonListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('person.created')
|
||||
@OnDatabaseEvent('person', DatabaseEventAction.CREATED)
|
||||
async handleCreatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordCreateEvent<PersonWorkspaceEntity>
|
||||
@ -47,7 +48,7 @@ export class MessageParticipantPersonListener {
|
||||
}
|
||||
}
|
||||
|
||||
@OnEvent('person.updated')
|
||||
@OnDatabaseEvent('person', DatabaseEventAction.UPDATED)
|
||||
async handleUpdatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordUpdateEvent<PersonWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
@ -24,6 +23,8 @@ import {
|
||||
MessageParticipantUnmatchParticipantJobData,
|
||||
} from 'src/modules/messaging/message-participant-manager/jobs/message-participant-unmatch-participant.job';
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class MessageParticipantWorkspaceMemberListener {
|
||||
@ -34,7 +35,7 @@ export class MessageParticipantWorkspaceMemberListener {
|
||||
private readonly workspaceRepository: Repository<Workspace>,
|
||||
) {}
|
||||
|
||||
@OnEvent('workspaceMember.created')
|
||||
@OnDatabaseEvent('workspaceMember', DatabaseEventAction.CREATED)
|
||||
async handleCreatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordCreateEvent<WorkspaceMemberWorkspaceEntity>
|
||||
@ -67,7 +68,7 @@ export class MessageParticipantWorkspaceMemberListener {
|
||||
}
|
||||
}
|
||||
|
||||
@OnEvent('workspaceMember.updated')
|
||||
@OnDatabaseEvent('workspaceMember', DatabaseEventAction.UPDATED)
|
||||
async handleUpdatedEvent(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordUpdateEvent<WorkspaceMemberWorkspaceEntity>
|
||||
|
||||
@ -20,15 +20,15 @@ export class CreateAuditLogFromInternalEvent {
|
||||
|
||||
@Process(CreateAuditLogFromInternalEvent.name)
|
||||
async handle(
|
||||
data: WorkspaceEventBatch<ObjectRecordBaseEvent>,
|
||||
workspaceEventBatch: WorkspaceEventBatch<ObjectRecordBaseEvent>,
|
||||
): Promise<void> {
|
||||
for (const eventData of data.events) {
|
||||
for (const eventData of workspaceEventBatch.events) {
|
||||
let workspaceMemberId: string | null = null;
|
||||
|
||||
if (eventData.userId) {
|
||||
const workspaceMember = await this.workspaceMemberService.getByIdOrFail(
|
||||
eventData.userId,
|
||||
data.workspaceId,
|
||||
workspaceEventBatch.workspaceId,
|
||||
);
|
||||
|
||||
workspaceMemberId = workspaceMember.id;
|
||||
@ -42,13 +42,13 @@ export class CreateAuditLogFromInternalEvent {
|
||||
}
|
||||
|
||||
await this.auditLogRepository.insert(
|
||||
data.name,
|
||||
workspaceEventBatch.name,
|
||||
eventData.properties,
|
||||
workspaceMemberId,
|
||||
data.name.split('.')[0],
|
||||
workspaceEventBatch.name.split('.')[0],
|
||||
eventData.objectMetadata.id,
|
||||
eventData.recordId,
|
||||
data.workspaceId,
|
||||
workspaceEventBatch.workspaceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,13 +18,13 @@ export class UpsertTimelineActivityFromInternalEvent {
|
||||
|
||||
@Process(UpsertTimelineActivityFromInternalEvent.name)
|
||||
async handle(
|
||||
data: WorkspaceEventBatch<ObjectRecordBaseEvent>,
|
||||
workspaceEventBatch: WorkspaceEventBatch<ObjectRecordBaseEvent>,
|
||||
): Promise<void> {
|
||||
for (const eventData of data.events) {
|
||||
for (const eventData of workspaceEventBatch.events) {
|
||||
if (eventData.userId) {
|
||||
const workspaceMember = await this.workspaceMemberService.getByIdOrFail(
|
||||
eventData.userId,
|
||||
data.workspaceId,
|
||||
workspaceEventBatch.workspaceId,
|
||||
);
|
||||
|
||||
eventData.workspaceMemberId = workspaceMember.id;
|
||||
@ -48,9 +48,9 @@ export class UpsertTimelineActivityFromInternalEvent {
|
||||
}
|
||||
|
||||
await this.timelineActivityService.upsertEvent({
|
||||
...eventData,
|
||||
workspaceId: data.workspaceId,
|
||||
name: data.name,
|
||||
event: eventData,
|
||||
eventName: workspaceEventBatch.name,
|
||||
workspaceId: workspaceEventBatch.workspaceId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { ObjectRecordBaseEventWithNameAndWorkspaceId } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { TimelineActivityRepository } from 'src/modules/timeline/repositiories/timeline-activity.repository';
|
||||
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
|
||||
|
||||
type TransformedEvent = ObjectRecordBaseEventWithNameAndWorkspaceId & {
|
||||
type TransformedEvent = ObjectRecordBaseEvent & {
|
||||
objectName?: string;
|
||||
linkedRecordCachedName?: string;
|
||||
linkedRecordId?: string;
|
||||
@ -26,18 +26,26 @@ export class TimelineActivityService {
|
||||
task: 'taskTarget',
|
||||
};
|
||||
|
||||
async upsertEvent(event: ObjectRecordBaseEventWithNameAndWorkspaceId) {
|
||||
const events = await this.transformEvent(event);
|
||||
async upsertEvent({
|
||||
event,
|
||||
eventName,
|
||||
workspaceId,
|
||||
}: {
|
||||
event: ObjectRecordBaseEvent;
|
||||
eventName: string;
|
||||
workspaceId: string;
|
||||
}) {
|
||||
const events = await this.transformEvent({ event, workspaceId, eventName });
|
||||
|
||||
if (!events || events.length === 0) return;
|
||||
|
||||
for (const event of events) {
|
||||
await this.timelineActivityRepository.upsertOne(
|
||||
event.name,
|
||||
eventName,
|
||||
event.properties,
|
||||
event.objectName ?? event.objectMetadata.nameSingular,
|
||||
event.recordId,
|
||||
event.workspaceId,
|
||||
workspaceId,
|
||||
event.workspaceMemberId,
|
||||
event.linkedRecordCachedName,
|
||||
event.linkedRecordId,
|
||||
@ -46,11 +54,21 @@ export class TimelineActivityService {
|
||||
}
|
||||
}
|
||||
|
||||
private async transformEvent(
|
||||
event: ObjectRecordBaseEventWithNameAndWorkspaceId,
|
||||
): Promise<TransformedEvent[]> {
|
||||
private async transformEvent({
|
||||
event,
|
||||
workspaceId,
|
||||
eventName,
|
||||
}: {
|
||||
event: ObjectRecordBaseEvent;
|
||||
workspaceId: string;
|
||||
eventName: string;
|
||||
}): Promise<TransformedEvent[]> {
|
||||
if (['note', 'task'].includes(event.objectMetadata.nameSingular)) {
|
||||
const linkedObjects = await this.handleLinkedObjects(event);
|
||||
const linkedObjects = await this.handleLinkedObjects({
|
||||
event,
|
||||
workspaceId,
|
||||
eventName,
|
||||
});
|
||||
|
||||
// 2 timelines, one for the linked object and one for the task/note
|
||||
if (linkedObjects?.length > 0) return [...linkedObjects, event];
|
||||
@ -61,56 +79,81 @@ export class TimelineActivityService {
|
||||
event.objectMetadata.nameSingular,
|
||||
)
|
||||
) {
|
||||
const linkedObjects = await this.handleLinkedObjects(event);
|
||||
|
||||
return linkedObjects;
|
||||
return await this.handleLinkedObjects({ event, workspaceId, eventName });
|
||||
}
|
||||
|
||||
return [event];
|
||||
}
|
||||
|
||||
private async handleLinkedObjects(
|
||||
event: ObjectRecordBaseEventWithNameAndWorkspaceId,
|
||||
) {
|
||||
const dataSourceSchema = this.workspaceDataSourceService.getSchemaName(
|
||||
event.workspaceId,
|
||||
);
|
||||
private async handleLinkedObjects({
|
||||
event,
|
||||
workspaceId,
|
||||
eventName,
|
||||
}: {
|
||||
event: ObjectRecordBaseEvent;
|
||||
workspaceId: string;
|
||||
eventName: string;
|
||||
}) {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
switch (event.objectMetadata.nameSingular) {
|
||||
case 'noteTarget':
|
||||
return this.processActivityTarget(event, dataSourceSchema, 'note');
|
||||
case 'taskTarget':
|
||||
return this.processActivityTarget(event, dataSourceSchema, 'task');
|
||||
case 'note':
|
||||
case 'task':
|
||||
return this.processActivity(
|
||||
return this.processActivityTarget({
|
||||
event,
|
||||
dataSourceSchema,
|
||||
event.objectMetadata.nameSingular,
|
||||
);
|
||||
activityType: 'note',
|
||||
eventName,
|
||||
workspaceId,
|
||||
});
|
||||
case 'taskTarget':
|
||||
return this.processActivityTarget({
|
||||
event,
|
||||
dataSourceSchema,
|
||||
activityType: 'task',
|
||||
eventName,
|
||||
workspaceId,
|
||||
});
|
||||
case 'note':
|
||||
case 'task':
|
||||
return this.processActivity({
|
||||
event,
|
||||
dataSourceSchema,
|
||||
activityType: event.objectMetadata.nameSingular,
|
||||
eventName,
|
||||
workspaceId,
|
||||
});
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private async processActivity(
|
||||
event: ObjectRecordBaseEventWithNameAndWorkspaceId,
|
||||
dataSourceSchema: string,
|
||||
activityType: string,
|
||||
) {
|
||||
private async processActivity({
|
||||
event,
|
||||
dataSourceSchema,
|
||||
activityType,
|
||||
eventName,
|
||||
workspaceId,
|
||||
}: {
|
||||
event: ObjectRecordBaseEvent;
|
||||
dataSourceSchema: string;
|
||||
activityType: string;
|
||||
eventName: string;
|
||||
workspaceId: string;
|
||||
}) {
|
||||
const activityTargets =
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT * FROM ${dataSourceSchema}."${this.targetObjects[activityType]}"
|
||||
WHERE "${activityType}Id" = $1`,
|
||||
[event.recordId],
|
||||
event.workspaceId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const activity = await this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT * FROM ${dataSourceSchema}."${activityType}"
|
||||
WHERE "id" = $1`,
|
||||
[event.recordId],
|
||||
event.workspaceId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (activityTargets.length === 0) return;
|
||||
@ -135,7 +178,7 @@ export class TimelineActivityService {
|
||||
|
||||
return {
|
||||
...event,
|
||||
name: 'linked-' + event.name,
|
||||
name: 'linked-' + eventName,
|
||||
objectName: targetColumn[0].replace(/Id$/, ''),
|
||||
recordId: activityTarget[targetColumn[0]],
|
||||
linkedRecordCachedName: activity[0].title,
|
||||
@ -146,17 +189,25 @@ export class TimelineActivityService {
|
||||
.filter((event): event is TransformedEvent => event !== undefined);
|
||||
}
|
||||
|
||||
private async processActivityTarget(
|
||||
event: ObjectRecordBaseEventWithNameAndWorkspaceId,
|
||||
dataSourceSchema: string,
|
||||
activityType: string,
|
||||
) {
|
||||
private async processActivityTarget({
|
||||
event,
|
||||
dataSourceSchema,
|
||||
activityType,
|
||||
eventName,
|
||||
workspaceId,
|
||||
}: {
|
||||
event: ObjectRecordBaseEvent;
|
||||
dataSourceSchema: string;
|
||||
activityType: string;
|
||||
eventName: string;
|
||||
workspaceId: string;
|
||||
}) {
|
||||
const activityTarget =
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT * FROM ${dataSourceSchema}."${this.targetObjects[activityType]}"
|
||||
WHERE "id" = $1`,
|
||||
[event.recordId],
|
||||
event.workspaceId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (activityTarget.length === 0) return;
|
||||
@ -165,7 +216,7 @@ export class TimelineActivityService {
|
||||
`SELECT * FROM ${dataSourceSchema}."${activityType}"
|
||||
WHERE "id" = $1`,
|
||||
[activityTarget[0].activityId],
|
||||
event.workspaceId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (activity.length === 0) return;
|
||||
@ -189,14 +240,14 @@ export class TimelineActivityService {
|
||||
return [
|
||||
{
|
||||
...event,
|
||||
name: 'linked-' + event.name,
|
||||
name: 'linked-' + eventName,
|
||||
properties: {},
|
||||
objectName: targetColumn[0].replace(/Id$/, ''),
|
||||
recordId: activityTarget[0][targetColumn[0]],
|
||||
linkedRecordCachedName: activity[0].title,
|
||||
linkedRecordId: activity[0].id,
|
||||
linkedObjectMetadataId: activityObjectMetadataId,
|
||||
},
|
||||
] as TransformedEvent[];
|
||||
} as TransformedEvent,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,90 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
import { ArrayContains } from 'typeorm';
|
||||
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { WebhookWorkspaceEntity } from 'src/modules/webhook/standard-objects/webhook.workspace-entity';
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/workspace-event.type';
|
||||
import {
|
||||
CallWebhookJob,
|
||||
CallWebhookJobData,
|
||||
} from 'src/modules/webhook/jobs/call-webhook.job';
|
||||
|
||||
@Processor(MessageQueue.webhookQueue)
|
||||
export class CallWebhookJobsJob {
|
||||
private readonly logger = new Logger(CallWebhookJobsJob.name);
|
||||
|
||||
constructor(
|
||||
@InjectMessageQueue(MessageQueue.webhookQueue)
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||
) {}
|
||||
|
||||
@Process(CallWebhookJobsJob.name)
|
||||
async handle(
|
||||
workspaceEventBatch: WorkspaceEventBatch<ObjectRecordBaseEvent>,
|
||||
): Promise<void> {
|
||||
// If you change that function, double check it does not break Zapier
|
||||
// trigger in packages/twenty-zapier/src/triggers/trigger_record.ts
|
||||
// Also change the openApi schema for webhooks
|
||||
// packages/twenty-server/src/engine/core-modules/open-api/utils/computeWebhooks.utils.ts
|
||||
|
||||
const webhookRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<WebhookWorkspaceEntity>(
|
||||
workspaceEventBatch.workspaceId,
|
||||
'webhook',
|
||||
);
|
||||
|
||||
const [nameSingular, operation] = workspaceEventBatch.name.split('.');
|
||||
|
||||
const webhooks = await webhookRepository.find({
|
||||
where: [
|
||||
{ operations: ArrayContains([`${nameSingular}.${operation}`]) },
|
||||
{ operations: ArrayContains([`*.${operation}`]) },
|
||||
{ operations: ArrayContains([`${nameSingular}.*`]) },
|
||||
{ operations: ArrayContains(['*.*']) },
|
||||
],
|
||||
});
|
||||
|
||||
for (const eventData of workspaceEventBatch.events) {
|
||||
const eventName = workspaceEventBatch.name;
|
||||
const objectMetadata = {
|
||||
id: eventData.objectMetadata.id,
|
||||
nameSingular: eventData.objectMetadata.nameSingular,
|
||||
};
|
||||
const workspaceId = workspaceEventBatch.workspaceId;
|
||||
const record = eventData.properties.after || eventData.properties.before;
|
||||
const updatedFields = eventData.properties.updatedFields;
|
||||
|
||||
webhooks.forEach((webhook) => {
|
||||
const webhookData = {
|
||||
targetUrl: webhook.targetUrl,
|
||||
eventName,
|
||||
objectMetadata,
|
||||
workspaceId,
|
||||
webhookId: webhook.id,
|
||||
eventDate: new Date(),
|
||||
record,
|
||||
...(updatedFields && { updatedFields }),
|
||||
};
|
||||
|
||||
this.messageQueueService.add<CallWebhookJobData>(
|
||||
CallWebhookJob.name,
|
||||
webhookData,
|
||||
{ retryLimit: 3 },
|
||||
);
|
||||
});
|
||||
|
||||
webhooks.length > 0 &&
|
||||
this.logger.log(
|
||||
`CallWebhookJobsJob on eventName '${workspaceEventBatch.name}' triggered webhooks with ids [\n"${webhooks.map((webhook) => webhook.id).join('",\n"')}"\n]`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
import { AnalyticsService } from 'src/engine/core-modules/analytics/analytics.service';
|
||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
|
||||
export type CallWebhookJobData = {
|
||||
targetUrl: string;
|
||||
eventName: string;
|
||||
objectMetadata: { id: string; nameSingular: string };
|
||||
workspaceId: string;
|
||||
webhookId: string;
|
||||
eventDate: Date;
|
||||
record: any;
|
||||
updatedFields?: string[];
|
||||
};
|
||||
|
||||
@Processor(MessageQueue.webhookQueue)
|
||||
export class CallWebhookJob {
|
||||
private readonly logger = new Logger(CallWebhookJob.name);
|
||||
constructor(
|
||||
private readonly httpService: HttpService,
|
||||
private readonly analyticsService: AnalyticsService,
|
||||
) {}
|
||||
|
||||
@Process(CallWebhookJob.name)
|
||||
async handle(data: CallWebhookJobData): Promise<void> {
|
||||
const commonPayload = {
|
||||
url: data.targetUrl,
|
||||
webhookId: data.webhookId,
|
||||
eventName: data.eventName,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await this.httpService.axiosRef.post(
|
||||
data.targetUrl,
|
||||
data,
|
||||
);
|
||||
const success = response.status >= 200 && response.status < 300;
|
||||
const eventInput = {
|
||||
action: 'webhook.response',
|
||||
payload: {
|
||||
status: response.status,
|
||||
success,
|
||||
...commonPayload,
|
||||
},
|
||||
};
|
||||
|
||||
this.analyticsService.create(eventInput, 'webhook', data.workspaceId);
|
||||
} catch (err) {
|
||||
const eventInput = {
|
||||
action: 'webhook.response',
|
||||
payload: {
|
||||
success: false,
|
||||
...commonPayload,
|
||||
...(err.response && { status: err.response.status }),
|
||||
},
|
||||
};
|
||||
|
||||
this.analyticsService.create(eventInput, 'webhook', data.workspaceId);
|
||||
this.logger.error(
|
||||
`Error calling webhook on targetUrl '${data.targetUrl}': ${err}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
|
||||
import { CallWebhookJobsJob } from 'src/modules/webhook/jobs/call-webhook-jobs.job';
|
||||
import { CallWebhookJob } from 'src/modules/webhook/jobs/call-webhook.job';
|
||||
import { AnalyticsModule } from 'src/engine/core-modules/analytics/analytics.module';
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule, AnalyticsModule],
|
||||
providers: [CallWebhookJobsJob, CallWebhookJob],
|
||||
})
|
||||
export class WebhookJobModule {}
|
||||
@ -16,6 +16,7 @@ import {
|
||||
WorkflowVersionWorkspaceEntity,
|
||||
} from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
||||
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@WorkspaceQueryHook({
|
||||
key: `workflow.createMany`,
|
||||
@ -62,7 +63,7 @@ export class WorkflowCreateManyPostQueryHook
|
||||
});
|
||||
|
||||
this.workspaceEventEmitter.emit(
|
||||
`workflowVersion.created`,
|
||||
`workflowVersion.${DatabaseEventAction.CREATED}`,
|
||||
workflowVersionsToCreate.map((workflowVersionToCreate) => {
|
||||
return {
|
||||
userId: authContext.user?.id,
|
||||
|
||||
@ -16,6 +16,7 @@ import {
|
||||
WorkflowVersionWorkspaceEntity,
|
||||
} from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
||||
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@WorkspaceQueryHook({
|
||||
key: `workflow.createOne`,
|
||||
@ -58,7 +59,7 @@ export class WorkflowCreateOnePostQueryHook
|
||||
});
|
||||
|
||||
this.workspaceEventEmitter.emit(
|
||||
`workflowVersion.created`,
|
||||
`workflowVersion.${DatabaseEventAction.CREATED}`,
|
||||
[
|
||||
{
|
||||
userId: authContext.user?.id,
|
||||
|
||||
@ -6,10 +6,11 @@ import { ObjectRecordDestroyEvent } from 'src/engine/core-modules/event-emitter/
|
||||
import { ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { generateFakeObjectRecord } from 'src/modules/workflow/workflow-builder/utils/generate-fake-object-record';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
export const generateFakeObjectRecordEvent = <Entity>(
|
||||
objectMetadataEntity: ObjectMetadataEntity,
|
||||
action: 'created' | 'updated' | 'deleted' | 'destroyed',
|
||||
action: DatabaseEventAction,
|
||||
):
|
||||
| ObjectRecordCreateEvent<Entity>
|
||||
| ObjectRecordUpdateEvent<Entity>
|
||||
@ -21,7 +22,7 @@ export const generateFakeObjectRecordEvent = <Entity>(
|
||||
|
||||
const after = generateFakeObjectRecord<Entity>(objectMetadataEntity);
|
||||
|
||||
if (action === 'created') {
|
||||
if (action === DatabaseEventAction.CREATED) {
|
||||
return {
|
||||
recordId,
|
||||
userId,
|
||||
@ -35,7 +36,7 @@ export const generateFakeObjectRecordEvent = <Entity>(
|
||||
|
||||
const before = generateFakeObjectRecord<Entity>(objectMetadataEntity);
|
||||
|
||||
if (action === 'updated') {
|
||||
if (action === DatabaseEventAction.UPDATED) {
|
||||
return {
|
||||
recordId,
|
||||
userId,
|
||||
@ -44,12 +45,11 @@ export const generateFakeObjectRecordEvent = <Entity>(
|
||||
properties: {
|
||||
before,
|
||||
after,
|
||||
diff: after,
|
||||
},
|
||||
} satisfies ObjectRecordUpdateEvent<Entity>;
|
||||
}
|
||||
|
||||
if (action === 'deleted') {
|
||||
if (action === DatabaseEventAction.DELETED) {
|
||||
return {
|
||||
recordId,
|
||||
userId,
|
||||
@ -61,7 +61,7 @@ export const generateFakeObjectRecordEvent = <Entity>(
|
||||
} satisfies ObjectRecordDeleteEvent<Entity>;
|
||||
}
|
||||
|
||||
if (action === 'destroyed') {
|
||||
if (action === DatabaseEventAction.DESTROYED) {
|
||||
return {
|
||||
recordId,
|
||||
userId,
|
||||
|
||||
@ -5,7 +5,6 @@ import { join } from 'path';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { generateFakeObjectRecordEvent } from 'src/engine/core-modules/event-emitter/utils/generate-fake-object-record-event';
|
||||
import { INDEX_FILE_NAME } from 'src/engine/core-modules/serverless/drivers/constants/index-file-name';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
|
||||
@ -21,6 +20,9 @@ import {
|
||||
WorkflowTriggerType,
|
||||
} from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type';
|
||||
import { isDefined } from 'src/utils/is-defined';
|
||||
import { checkStringIsDatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/utils/check-string-is-database-event-action';
|
||||
import { generateFakeObjectRecordEvent } from 'src/modules/workflow/workflow-builder/utils/generate-fake-object-record-event';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class WorkflowBuilderService {
|
||||
@ -92,7 +94,7 @@ export class WorkflowBuilderService {
|
||||
}) {
|
||||
const [nameSingular, action] = eventName.split('.');
|
||||
|
||||
if (!['created', 'updated', 'deleted', 'destroyed'].includes(action)) {
|
||||
if (!checkStringIsDatabaseEventAction(action)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -110,7 +112,7 @@ export class WorkflowBuilderService {
|
||||
|
||||
return generateFakeObjectRecordEvent(
|
||||
objectMetadata,
|
||||
action as 'created' | 'updated' | 'deleted' | 'destroyed',
|
||||
action as DatabaseEventAction,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
@ -17,6 +16,8 @@ import {
|
||||
WorkflowVersionEventType,
|
||||
WorkflowVersionStatusUpdate,
|
||||
} from 'src/modules/workflow/workflow-status/jobs/workflow-statuses-update.job';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class WorkflowVersionStatusListener {
|
||||
@ -25,7 +26,7 @@ export class WorkflowVersionStatusListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('workflowVersion.created')
|
||||
@OnDatabaseEvent('workflowVersion', DatabaseEventAction.CREATED)
|
||||
async handleWorkflowVersionCreated(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordCreateEvent<WorkflowVersionWorkspaceEntity>
|
||||
@ -53,7 +54,7 @@ export class WorkflowVersionStatusListener {
|
||||
);
|
||||
}
|
||||
|
||||
@OnEvent('workflowVersion.statusUpdated')
|
||||
@OnDatabaseEvent('workflowVersion', DatabaseEventAction.UPDATED)
|
||||
async handleWorkflowVersionUpdated(
|
||||
payload: WorkspaceEventBatch<WorkflowVersionStatusUpdate>,
|
||||
): Promise<void> {
|
||||
@ -67,7 +68,7 @@ export class WorkflowVersionStatusListener {
|
||||
);
|
||||
}
|
||||
|
||||
@OnEvent('workflowVersion.deleted')
|
||||
@OnDatabaseEvent('workflowVersion', DatabaseEventAction.DELETED)
|
||||
async handleWorkflowVersionDeleted(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordDeleteEvent<WorkflowVersionWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
@ -17,6 +16,8 @@ import {
|
||||
WorkflowEventTriggerJob,
|
||||
WorkflowEventTriggerJobData,
|
||||
} from 'src/modules/workflow/workflow-trigger/jobs/workflow-event-trigger.job';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class DatabaseEventTriggerListener {
|
||||
@ -29,28 +30,28 @@ export class DatabaseEventTriggerListener {
|
||||
private readonly isFeatureFlagEnabledService: FeatureFlagService,
|
||||
) {}
|
||||
|
||||
@OnEvent('*.created')
|
||||
@OnDatabaseEvent('*', DatabaseEventAction.CREATED)
|
||||
async handleObjectRecordCreateEvent(
|
||||
payload: WorkspaceEventBatch<ObjectRecordCreateEvent<any>>,
|
||||
) {
|
||||
await this.handleEvent(payload);
|
||||
}
|
||||
|
||||
@OnEvent('*.updated')
|
||||
@OnDatabaseEvent('*', DatabaseEventAction.UPDATED)
|
||||
async handleObjectRecordUpdateEvent(
|
||||
payload: WorkspaceEventBatch<ObjectRecordUpdateEvent<any>>,
|
||||
) {
|
||||
await this.handleEvent(payload);
|
||||
}
|
||||
|
||||
@OnEvent('*.deleted')
|
||||
@OnDatabaseEvent('*', DatabaseEventAction.DELETED)
|
||||
async handleObjectRecordDeleteEvent(
|
||||
payload: WorkspaceEventBatch<ObjectRecordDeleteEvent<any>>,
|
||||
) {
|
||||
await this.handleEvent(payload);
|
||||
}
|
||||
|
||||
@OnEvent('*.destroyed')
|
||||
@OnDatabaseEvent('*', DatabaseEventAction.DESTROYED)
|
||||
async handleObjectRecordDestroyEvent(
|
||||
payload: WorkspaceEventBatch<ObjectRecordDestroyEvent<any>>,
|
||||
) {
|
||||
|
||||
@ -25,6 +25,7 @@ import {
|
||||
import { WorkflowTriggerType } from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type';
|
||||
import { assertVersionCanBeActivated } from 'src/modules/workflow/workflow-trigger/utils/assert-version-can-be-activated.util';
|
||||
import { assertNever } from 'src/utils/assert';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class WorkflowTriggerWorkspaceService {
|
||||
@ -362,7 +363,7 @@ export class WorkflowTriggerWorkspaceService {
|
||||
}
|
||||
|
||||
this.workspaceEventEmitter.emit(
|
||||
'workflowVersion.statusUpdated',
|
||||
`workflowVersion.${DatabaseEventAction.UPDATED}`,
|
||||
[
|
||||
{
|
||||
workflowId,
|
||||
|
||||
Reference in New Issue
Block a user