Skip to content

Commit

Permalink
馃悰 Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mit-27 committed May 10, 2024
1 parent d3a0199 commit 7f12892
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 32 deletions.
47 changes: 36 additions & 11 deletions packages/api/src/ticketing/comment/services/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,38 @@ export class GitlabService implements ICommentService {
attachments: uploads,
};

const ticket = await this.prisma.tcg_tickets.findUnique({
const ticket = await this.prisma.tcg_tickets.findFirst({
where: {
id_tcg_ticket: remoteIdTicket,
remote_id: remoteIdTicket,
remote_platform: 'gitlab',
},
select: {
collections: true
},
collections: true,
id_tcg_ticket: true
}
});

const remote_project_id = await this.utils.getCollectionRemoteIdFromUuid(ticket.collections[0])



// const ticket = await this.prisma.tcg_tickets.findUnique({
// where: {
// id_tcg_ticket: remoteIdTicket,
// },
// select: {
// collections: true
// },
// });

const remote_project_id = await this.utils.getCollectionRemoteIdFromUuid(ticket.collections[0]);

// Retrieve the uuid of issue from remote_data
const remote_data = await this.prisma.remote_data.findFirst({
where: {
ressource_owner_id: ticket.id_tcg_ticket,
},
});
const { iid } = JSON.parse(remote_data.data);

const resp = await axios.post(
`${connection.account_url}/projects/${remote_project_id}/issues/${remoteIdTicket}/notes`,
`${connection.account_url}/projects/${remote_project_id}/issues/${iid}/notes`,
JSON.stringify(data),
{
headers: {
Expand Down Expand Up @@ -145,9 +159,19 @@ export class GitlabService implements ICommentService {
// retrieve the remote_id of project from collections
const remote_project_id = await this.utils.getCollectionRemoteIdFromUuid(ticket.collections[0])

// Retrieve the uuid of issue from remote_data
const remote_data = await this.prisma.remote_data.findFirst({
where: {
ressource_owner_id: id_ticket,
},
});
const { iid } = JSON.parse(remote_data.data);

console.log("Requested URL : ", `${connection.account_url}/projects/${remote_project_id}/issues/${iid}/notes`)


const resp = await axios.get(
`${connection.account_url}/projects/${remote_project_id}/issues/${ticket.remote_id}/notes`,
`${connection.account_url}/projects/${remote_project_id}/issues/${iid}/notes`,
{
headers: {
'Content-Type': 'application/json',
Expand All @@ -158,9 +182,10 @@ export class GitlabService implements ICommentService {
},
);
this.logger.log(`Synced gitlab comments !`);
console.log(resp.data)

return {
data: resp.data._results,
data: resp.data,
message: 'Gitlab comments retrieved',
statusCode: 200,
};
Expand Down
11 changes: 8 additions & 3 deletions packages/api/src/ticketing/comment/services/gitlab/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export class GitlabCommentMapper implements ICommentMapper {
String(comment.author.id),
'gitlab',
);
opts.user_id = user_id;
if (user_id) {
opts.user_id = user_id;
}
}

// if (user_id) {
Expand All @@ -100,10 +102,13 @@ export class GitlabCommentMapper implements ICommentMapper {
// }
if (comment.noteable_id) {
const ticket_id = await this.utils.getTicketUuidFromRemoteId(
String(comment.noteable_id),
String(comment.noteable_iid),
'gitlab'
)
opts.ticket_id = ticket_id;
if (ticket_id) {
opts.ticket_id = ticket_id;

}
}

const res: UnifiedCommentOutput = {
Expand Down
17 changes: 9 additions & 8 deletions packages/api/src/ticketing/comment/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class SyncService implements OnModuleInit {
}
//function used by sync worker which populate our tcg_comments table
//its role is to fetch all comments from providers 3rd parties and save the info inside our db
//@Cron('*/2 * * * *') // every 2 minutes (for testing)
// @Cron('*/2 * * * *') // every 2 minutes (for testing)
@Cron('0 */8 * * *') // every 8 hours
async syncComments(user_id?: string) {
try {
Expand Down Expand Up @@ -189,9 +189,9 @@ export class SyncService implements OnModuleInit {
data: {
id_event: uuidv4(),
status: 'success',
type: 'ticketing.comment.synced',
method: 'SYNC',
url: '/sync',
type: 'ticketing.comment.pulled',
method: 'PULL',
url: '/pull',
provider: integrationId,
direction: '0',
timestamp: new Date(),
Expand All @@ -200,7 +200,7 @@ export class SyncService implements OnModuleInit {
});
await this.webhook.handleWebhook(
comments_data,
'ticketing.comment.synced',
'ticketing.comment.pulled',
id_project,
event.id_event,
);
Expand Down Expand Up @@ -236,15 +236,16 @@ export class SyncService implements OnModuleInit {

let unique_ticketing_comment_id: string;
const opts =
comment.creator_type === 'contact'
(comment.creator_type === 'CONTACT' && comment.contact_id)
? {
id_tcg_contact: comment.contact_id,
}
: comment.creator_type === 'user'
: (comment.creator_type === 'USER' && comment.user_id)
? {
id_tcg_user: comment.user_id,
}
: {}; //case where nothing is passed for creator or a not authorized value;
: {};
//case where nothing is passed for creator or a not authorized value;

if (existingComment) {
// Update the existing comment
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/ticketing/ticket/services/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class GitlabService implements ITicketService {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'github',
provider_slug: 'gitlab',
vertical: 'ticketing',
},
});
Expand Down Expand Up @@ -73,7 +73,7 @@ export class GitlabService implements ITicketService {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'github',
provider_slug: 'gitlab',
vertical: 'ticketing',
},
});
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/ticketing/ticket/services/gitlab/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class GitlabTicketMapper implements ITicketMapper {

let opts: any;
if (ticket.type) {
opts.type = ticket.type === "opened" ? "OPEN" : "CLOSED"
opts = { ...opts, type: ticket.type === "opened" ? "OPEN" : "CLOSED" }
}

if (ticket.assignee) {
Expand All @@ -108,7 +108,7 @@ export class GitlabTicketMapper implements ITicketMapper {
'gitlab',
);
if (user_id) {
opts = { assigned_to: [user_id] };
opts = { ...opts, assigned_to: [user_id] };
}
}

Expand All @@ -118,7 +118,7 @@ export class GitlabTicketMapper implements ITicketMapper {
'gitlab'
);
if (tcg_collection_id) {
opts = { project_id: tcg_collection_id }
opts = { ...opts, project_id: tcg_collection_id }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ export class TicketService {
completed_at: ticket.completed_at || null,
priority: ticket.priority || '',
assigned_to: ticket.assigned_to || [],
collections: ticket.collections || [],
field_mappings: field_mappings,
};
}),
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/ticketing/ticket/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class SyncService implements OnModuleInit {
}
//function used by sync worker which populate our tcg_tickets table
//its role is to fetch all contacts from providers 3rd parties and save the info inside our db
//@Cron('*/2 * * * *') // every 2 minutes (for testing)
// @Cron('*/2 * * * *') // every 2 minutes (for testing)
@Cron('0 */8 * * *') // every 8 hours
async syncTickets(user_id?: string) {
try {
Expand Down Expand Up @@ -178,9 +178,9 @@ export class SyncService implements OnModuleInit {
data: {
id_event: uuidv4(),
status: 'success',
type: 'ticketing.ticket.synced',
method: 'SYNC',
url: '/sync',
type: 'ticketing.ticket.pulled',
method: 'PULL',
url: '/pull',
provider: integrationId,
direction: '0',
timestamp: new Date(),
Expand All @@ -190,7 +190,7 @@ export class SyncService implements OnModuleInit {

await this.webhook.handleWebhook(
tickets_data,
'ticketing.ticket.synced',
'ticketing.ticket.pulled',
id_project,
event.id_event,
);
Expand Down

0 comments on commit 7f12892

Please sign in to comment.