diff --git a/packages/api/src/ticketing/attachment/services/attachment.service.ts b/packages/api/src/ticketing/attachment/services/attachment.service.ts index 0ea02abc9..9875ff5e0 100644 --- a/packages/api/src/ticketing/attachment/services/attachment.service.ts +++ b/packages/api/src/ticketing/attachment/services/attachment.service.ts @@ -330,26 +330,10 @@ export class AttachmentService { ): Promise> { try { //TODO: handle case where data is not there (not synced) or old synced - const job_resp_create = await this.prisma.events.create({ - data: { - id_event: uuidv4(), - status: 'initialized', - type: 'ticketing.attachment.pull', - method: 'GET', - url: '/ticketing/attachment', - provider: integrationId, - direction: '0', - timestamp: new Date(), - id_linked_user: linkedUserId, - }, - }); - const job_id = job_resp_create.id_event; const attachments = await this.prisma.tcg_attachments.findMany({ where: { remote_id: integrationId.toLowerCase(), - events: { - id_linked_user: linkedUserId, - }, + id_linked_user: linkedUserId, }, }); @@ -410,12 +394,18 @@ export class AttachmentService { remote_data: remote_array_data, }; } - await this.prisma.events.update({ - where: { - id_event: job_id, - }, + + const event = await this.prisma.events.create({ data: { + id_event: uuidv4(), status: 'success', + type: 'ticketing.attachment.pull', + method: 'GET', + url: '/ticketing/attachment', + provider: integrationId, + direction: '0', + timestamp: new Date(), + id_linked_user: linkedUserId, }, }); diff --git a/packages/api/src/ticketing/attachment/sync/sync.service.ts b/packages/api/src/ticketing/attachment/sync/sync.service.ts index d6a9b1afc..e7705ec38 100644 --- a/packages/api/src/ticketing/attachment/sync/sync.service.ts +++ b/packages/api/src/ticketing/attachment/sync/sync.service.ts @@ -112,21 +112,7 @@ export class SyncService implements OnModuleInit { provider_slug: integrationId, }, }); - if (!connection) return; - const job_resp_create = await this.prisma.events.create({ - data: { - id_event: uuidv4(), - status: 'initialized', - type: 'ticketing.attachment.pulled', - method: 'PULL', - url: '/pull', - provider: integrationId, - direction: '0', - timestamp: new Date(), - id_linked_user: linkedUserId, - }, - }); - const job_id = job_resp_create.id_event; + if (!connection) throw new Error('connection not found'); // get potential fieldMappings and extract the original properties name const customFieldMappings = @@ -165,22 +151,26 @@ export class SyncService implements OnModuleInit { attachmentsIds, integrationId, id_ticket, - job_id, sourceObject, ); - await this.prisma.events.update({ - where: { - id_event: job_id, - }, + const event = await this.prisma.events.create({ data: { + id_event: uuidv4(), status: 'success', + type: 'ticketing.attachment.pulled', + method: 'PULL', + url: '/pull', + provider: integrationId, + direction: '0', + timestamp: new Date(), + id_linked_user: linkedUserId, }, }); await this.webhook.handleWebhook( attachments_data, 'ticketing.attachment.pulled', id_project, - job_id, + event.id_event, ); } catch (error) { handleServiceError(error, this.logger); @@ -193,7 +183,6 @@ export class SyncService implements OnModuleInit { originIds: string[], originSource: string, id_ticket: string, - jobId: string, remote_data: Record[], ): Promise { try { @@ -210,9 +199,7 @@ export class SyncService implements OnModuleInit { where: { remote_id: originId, remote_platform: originSource, - events: { - id_linked_user: linkedUserId, - }, + id_linked_user: linkedUserId, }, }); @@ -227,7 +214,6 @@ export class SyncService implements OnModuleInit { data: { //TODO id_tcg_ticket: id_ticket, - id_event: jobId, modified_at: new Date(), }, }); @@ -242,7 +228,7 @@ export class SyncService implements OnModuleInit { created_at: new Date(), modified_at: new Date(), id_tcg_ticket: id_ticket, - id_event: jobId, + id_linkedUser: linkedUserId, remote_id: originId, remote_platform: originSource, //TODO; id_tcg_contact String? @db.Uuid