Skip to content

Commit

Permalink
✨ Added remote_data
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Dec 12, 2023
1 parent 96a1357 commit 1ecc35a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
9 changes: 9 additions & 0 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,12 @@ model events {
@@index([id_linked_user], map: "fk_linkeduserid_projectid")
}

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
model remote_data {
id_remote_data String @id(map: "pk_remote_data") @db.Uuid
ressource_owner_id String? @unique(map: "force_unique_ressourceownerid") @db.Uuid
format String?
data String?
created_at DateTime? @db.Timestamp(6)
}
26 changes: 17 additions & 9 deletions packages/api/src/crm/contact/services/contact.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpStatus, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { PrismaService } from '@@core/prisma/prisma.service';
import { FreshSalesService } from './freshsales';
import { HubspotService } from './hubspot';
Expand Down Expand Up @@ -198,7 +198,6 @@ export class ContactService {
remote_data?: boolean,
): Promise<ApiResponse<ContactResponse>> {
try {
// handle case for remote data too
//TODO: handle case where data is not there (not synced) or old synced
const job_resp_create = await this.prisma.events.create({
data: {
Expand Down Expand Up @@ -270,19 +269,28 @@ export class ContactService {
}),
);

const res: ContactResponse = {
let res: ContactResponse = {
contacts: unifiedContacts,
};

//TODO
/*if (remote_data) {
const resp = await this.prisma.remote_data
if (remote_data) {
const remote_array_data: Record<string, any>[] = await Promise.all(
contacts.map(async (contact) => {
const resp = await this.prisma.remote_data.findFirst({
where: {
ressource_owner_id: contact.id_crm_contact,
},
});
const remote_data = JSON.parse(resp.data);
return remote_data;
}),
);

res = {
...res,
remote_data: [resp.data],
remote_data: remote_array_data,
};
}*/
}
await this.prisma.events.update({
where: {
id_event: job_id,
Expand Down
17 changes: 10 additions & 7 deletions packages/api/src/crm/contact/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,23 @@ export class SyncContactsService implements OnModuleInit {
}
}

//TODO: insert remote_data in db
/*await this.prisma.remote_data.upsert({
//insert remote_data in db
await this.prisma.remote_data.upsert({
where: {
id_crm_contact: unique_crm_contact_id,
ressource_owner_id: unique_crm_contact_id,
},
create: {
id_remote_data: uuidv4(),
id_crm_contact: unique_crm_contact_id,
data: remote_data,
ressource_owner_id: unique_crm_contact_id,
format: 'json',
data: JSON.stringify(remote_data[i]),
created_at: new Date(),
},
update: {
data: remote_data,
data: JSON.stringify(remote_data[i]),
created_at: new Date(),
},
});*/
});
}
} catch (error) {
handleServiceError(error, this.logger);
Expand Down

0 comments on commit 1ecc35a

Please sign in to comment.