Skip to content

Commit

Permalink
🚧 Updated jobs syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jan 5, 2024
1 parent 3285079 commit a9b030b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,26 +330,10 @@ export class AttachmentService {
): Promise<ApiResponse<AttachmentResponse>> {
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,
},
});

Expand Down Expand Up @@ -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,
},
});

Expand Down
40 changes: 13 additions & 27 deletions packages/api/src/ticketing/attachment/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
Expand All @@ -193,7 +183,6 @@ export class SyncService implements OnModuleInit {
originIds: string[],
originSource: string,
id_ticket: string,
jobId: string,
remote_data: Record<string, any>[],
): Promise<TicketingAttachment[]> {
try {
Expand All @@ -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,
},
});

Expand All @@ -227,7 +214,6 @@ export class SyncService implements OnModuleInit {
data: {
//TODO
id_tcg_ticket: id_ticket,
id_event: jobId,
modified_at: new Date(),
},
});
Expand All @@ -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
Expand Down

0 comments on commit a9b030b

Please sign in to comment.