From bc5ee343621317ca640accf7b49789d7f689ffd1 Mon Sep 17 00:00:00 2001 From: nael Date: Tue, 31 Oct 2023 00:39:54 +0100 Subject: [PATCH 1/7] feat: started add-contact integration --- packages/api/package.json | 3 +- .../crm/contact/services/contact.service.ts | 89 ++++++++++++++++--- .../crm/contact/services/freshsales/index.ts | 7 +- .../crm/contact/services/freshsales/types.ts | 32 +++++++ .../src/crm/contact/services/hubspot/index.ts | 3 +- .../src/crm/contact/services/hubspot/types.ts | 3 + .../crm/contact/services/pipedrive/index.ts | 4 +- .../crm/contact/services/pipedrive/types.ts | 3 + .../src/crm/contact/services/zendesk/index.ts | 3 +- .../src/crm/contact/services/zendesk/types.ts | 3 + .../src/crm/contact/services/zoho/index.ts | 4 +- .../src/crm/contact/services/zoho/types.ts | 3 + packages/api/src/crm/contact/types/index.ts | 12 +++ 13 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 packages/api/src/crm/contact/services/freshsales/types.ts create mode 100644 packages/api/src/crm/contact/services/hubspot/types.ts create mode 100644 packages/api/src/crm/contact/services/pipedrive/types.ts create mode 100644 packages/api/src/crm/contact/services/zendesk/types.ts create mode 100644 packages/api/src/crm/contact/services/zoho/types.ts create mode 100644 packages/api/src/crm/contact/types/index.ts diff --git a/packages/api/package.json b/packages/api/package.json index 47f5a7f7c..a14447c14 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -29,7 +29,8 @@ "@prisma/client": "^5.4.2", "axios": "^1.5.1", "reflect-metadata": "^0.1.13", - "rxjs": "^7.8.1" + "rxjs": "^7.8.1", + "uuid": "^9.0.1" }, "devDependencies": { "@nestjs/cli": "^10.0.0", diff --git a/packages/api/src/crm/contact/services/contact.service.ts b/packages/api/src/crm/contact/services/contact.service.ts index c0edf056a..ff1b015b2 100644 --- a/packages/api/src/crm/contact/services/contact.service.ts +++ b/packages/api/src/crm/contact/services/contact.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { HttpStatus, Injectable } from '@nestjs/common'; import { CreateContactDto } from '../dto/create-contact.dto'; import { PrismaService } from 'src/prisma/prisma.service'; import { FreshSalesService } from './freshsales'; @@ -6,6 +6,22 @@ import { HubspotService } from './hubspot'; import { ZohoService } from './zoho'; import { ZendeskService } from './zendesk'; import { PipedriveService } from './pipedrive'; +import { v4 as uuidv4 } from 'uuid'; +import { + ApiResponse, + FreshSales_ContactCreated, + Hubspot_ContactCreated, + Pipedrive_ContactCreated, + Zendesk_ContactCreated, + Zoho_ContactCreated, +} from '../types'; + +type AddContactResponse = + | FreshSales_ContactCreated + | Hubspot_ContactCreated + | Zendesk_ContactCreated + | Pipedrive_ContactCreated + | Zoho_ContactCreated; @Injectable() export class ContactService { @@ -18,20 +34,65 @@ export class ContactService { public pipedrive: PipedriveService, ) {} + //utils functions + async addContactToDb(data: CreateContactDto, job_uuid: string) { + const { first_name, last_name, email_addresses, phone_numbers } = data; + const uuid_crm_contact = uuidv4(); + const resp = await this.prisma.crm_contacts.create({ + data: { + id_crm_contact: 10, + uuid_crm_contact: uuid_crm_contact, + first_name: first_name, + last_name: last_name, + // TODO: job_uuid: job_uuid, + }, + }); + for (const mail of email_addresses) { + const resp_mail = await this.prisma.crm_contact_email_addresses.create({ + data: { + id_crm_contact_email: 1, + uuid_crm_contact_email: uuidv4(), + uuid_crm_contact: uuid_crm_contact, + email_address: mail, + email_address_type: '', + }, + }); + } + for (const mobile of phone_numbers) { + const resp_mobile = await this.prisma.crm_contacts_phone_numbers.create({ + data: { + id_crm_contacts_phone_number: 1, + uuid_crm_contacts_phone_number: uuidv4(), + uuid_crm_contact: uuid_crm_contact, + phone: mobile, + phone_type: '', + }, + }); + } + } + async addContact(createContactDto: CreateContactDto, integrationId: string) { - //TODO: add createContact info body to DB => addToDbBackup() - // 1. insert job_db => status: INITIALIZED uuid_job - // uuid_job - // 2. insert inside crm_contact DB uuid_job - // uuid_contact - // update job_db => status: WRITTEN + const job_uuid = uuidv4(); + /* TODO: const job_resp_create = await this.prisma.jobs.create({ + data: { + status: 'initialized' + } + })*/ + await this.addContactToDb(createContactDto, job_uuid); + /* TODO: const job_resp_update = await this.prisma.jobs.update({ + data: { + status: 'written' + }, where: { + job_uuid: job_uuid + } + })*/ //TODO: get the destination provider => call destinationCRMInDb() - const dest = {}; - let resp; //{data: {freshsales rep}, code: }; + const dest: any = 'freshsales'; + let resp: ApiResponse; switch (dest) { case 'freshsales': - resp = await this.freshsales.addContact(); + resp = await this.freshsales.addContact(createContactDto); break; case 'zoho': @@ -55,7 +116,15 @@ export class ContactService { } //TODO: sanitize the resp to normalize it + const status_resp = resp.statusCode === HttpStatus.OK ? 'success' : 'fail'; //3. update job_db => status: SUCCESS/FAIL + /* TODO: const job_resp = await this.prisma.jobs.update({ + data: { + status: status_resp + }, where: { + job_uuid: job_uuid + } + })*/ return resp; } } diff --git a/packages/api/src/crm/contact/services/freshsales/index.ts b/packages/api/src/crm/contact/services/freshsales/index.ts index 8a52264ed..1ad98fa8e 100644 --- a/packages/api/src/crm/contact/services/freshsales/index.ts +++ b/packages/api/src/crm/contact/services/freshsales/index.ts @@ -1,8 +1,13 @@ import { Injectable } from '@nestjs/common'; +import { CreateContactDto } from '../../dto/create-contact.dto'; +import { ApiResponse } from '../../types'; +import { FreshSales_ContactCreated } from './types'; @Injectable() export class FreshSalesService { - async addContact() { + async addContact( + createContactDto: CreateContactDto, + ): Promise> { return; } } diff --git a/packages/api/src/crm/contact/services/freshsales/types.ts b/packages/api/src/crm/contact/services/freshsales/types.ts new file mode 100644 index 000000000..c4c65ba5f --- /dev/null +++ b/packages/api/src/crm/contact/services/freshsales/types.ts @@ -0,0 +1,32 @@ +export interface FreshSales_ContactCreated { + id: number; + first_name: string; + last_name: string; + display_name: string; + avatar: string | null; + job_title: string | null; + city: string | null; + state: string | null; + zipcode: string | null; + country: string | null; + email: string | null; + time_zone: string | null; + work_number: string | null; + mobile_number: string; + address: string | null; + last_seen: string | null; + lead_score: number; + last_contacted: string | null; + open_deals_amount: string; + links: { + conversations: string; + activities: string; + }; + custom_field: Record; + updated_at: string; + keyword: string | null; + medium: string | null; + facebook: string | null; + twitter: string | null; + linkedin: string | null; +} diff --git a/packages/api/src/crm/contact/services/hubspot/index.ts b/packages/api/src/crm/contact/services/hubspot/index.ts index 7aecb32a4..6740974e2 100644 --- a/packages/api/src/crm/contact/services/hubspot/index.ts +++ b/packages/api/src/crm/contact/services/hubspot/index.ts @@ -1,8 +1,9 @@ import { Injectable } from '@nestjs/common'; +import { ApiResponse, Hubspot_ContactCreated } from '../../types'; @Injectable() export class HubspotService { - async addContact() { + async addContact(): Promise> { return; } } diff --git a/packages/api/src/crm/contact/services/hubspot/types.ts b/packages/api/src/crm/contact/services/hubspot/types.ts new file mode 100644 index 000000000..b6dd1047f --- /dev/null +++ b/packages/api/src/crm/contact/services/hubspot/types.ts @@ -0,0 +1,3 @@ +export interface Hubspot_ContactCreated { + id: number; +} diff --git a/packages/api/src/crm/contact/services/pipedrive/index.ts b/packages/api/src/crm/contact/services/pipedrive/index.ts index 7aa52fa02..ccadbdf6d 100644 --- a/packages/api/src/crm/contact/services/pipedrive/index.ts +++ b/packages/api/src/crm/contact/services/pipedrive/index.ts @@ -1,8 +1,10 @@ import { Injectable } from '@nestjs/common'; +import { Pipedrive_ContactCreated } from './types'; +import { ApiResponse } from '../../types'; @Injectable() export class PipedriveService { - async addContact() { + async addContact(): Promise> { return; } } diff --git a/packages/api/src/crm/contact/services/pipedrive/types.ts b/packages/api/src/crm/contact/services/pipedrive/types.ts new file mode 100644 index 000000000..ef647ae85 --- /dev/null +++ b/packages/api/src/crm/contact/services/pipedrive/types.ts @@ -0,0 +1,3 @@ +export interface Pipedrive_ContactCreated { + id: number; +} diff --git a/packages/api/src/crm/contact/services/zendesk/index.ts b/packages/api/src/crm/contact/services/zendesk/index.ts index af140aedc..daaa8a03b 100644 --- a/packages/api/src/crm/contact/services/zendesk/index.ts +++ b/packages/api/src/crm/contact/services/zendesk/index.ts @@ -1,8 +1,9 @@ import { Injectable } from '@nestjs/common'; +import { ApiResponse, Zendesk_ContactCreated } from '../../types'; @Injectable() export class ZendeskService { - async addContact() { + async addContact(): Promise> { return; } } diff --git a/packages/api/src/crm/contact/services/zendesk/types.ts b/packages/api/src/crm/contact/services/zendesk/types.ts new file mode 100644 index 000000000..ba89552c9 --- /dev/null +++ b/packages/api/src/crm/contact/services/zendesk/types.ts @@ -0,0 +1,3 @@ +export interface Zendesk_ContactCreated { + id: number; +} diff --git a/packages/api/src/crm/contact/services/zoho/index.ts b/packages/api/src/crm/contact/services/zoho/index.ts index 86681fcc4..308aa6076 100644 --- a/packages/api/src/crm/contact/services/zoho/index.ts +++ b/packages/api/src/crm/contact/services/zoho/index.ts @@ -1,8 +1,10 @@ import { Injectable } from '@nestjs/common'; +import { Zoho_ContactCreated } from './types'; +import { ApiResponse } from '../../types'; @Injectable() export class ZohoService { - async addContact() { + async addContact(): Promise> { return; } } diff --git a/packages/api/src/crm/contact/services/zoho/types.ts b/packages/api/src/crm/contact/services/zoho/types.ts new file mode 100644 index 000000000..f01cd96ff --- /dev/null +++ b/packages/api/src/crm/contact/services/zoho/types.ts @@ -0,0 +1,3 @@ +export interface Zoho_ContactCreated { + id: number; +} diff --git a/packages/api/src/crm/contact/types/index.ts b/packages/api/src/crm/contact/types/index.ts new file mode 100644 index 000000000..ee50d2071 --- /dev/null +++ b/packages/api/src/crm/contact/types/index.ts @@ -0,0 +1,12 @@ +export * from './../services/freshsales/types'; +export * from './../services/hubspot/types'; +export * from './../services/zoho/types'; +export * from './../services/zendesk/types'; +export * from './../services/pipedrive/types'; + +export class ApiResponse { + data: T; + message?: string; + error?: string; + statusCode: number; +} From 6744138c326dabee568d05e8e417fb382391e2bb Mon Sep 17 00:00:00 2001 From: nael Date: Tue, 31 Oct 2023 01:09:38 +0100 Subject: [PATCH 2/7] feat: added addContact function in freshsales service --- .../crm/contact/services/contact.service.ts | 8 ++-- .../crm/contact/services/freshsales/index.ts | 41 ++++++++++++++++++- .../src/crm/contact/services/hubspot/index.ts | 5 ++- .../crm/contact/services/pipedrive/index.ts | 5 ++- .../src/crm/contact/services/zendesk/index.ts | 5 ++- .../src/crm/contact/services/zoho/index.ts | 5 ++- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/packages/api/src/crm/contact/services/contact.service.ts b/packages/api/src/crm/contact/services/contact.service.ts index ff1b015b2..ea027f552 100644 --- a/packages/api/src/crm/contact/services/contact.service.ts +++ b/packages/api/src/crm/contact/services/contact.service.ts @@ -96,19 +96,19 @@ export class ContactService { break; case 'zoho': - resp = await this.zoho.addContact(); + resp = await this.zoho.addContact(createContactDto); break; case 'zendesk': - resp = await this.zendesk.addContact(); + resp = await this.zendesk.addContact(createContactDto); break; case 'hubspot': - resp = await this.hubspot.addContact(); + resp = await this.hubspot.addContact(createContactDto); break; case 'pipedrive': - resp = await this.pipedrive.addContact(); + resp = await this.pipedrive.addContact(createContactDto); break; default: diff --git a/packages/api/src/crm/contact/services/freshsales/index.ts b/packages/api/src/crm/contact/services/freshsales/index.ts index 1ad98fa8e..8f279a106 100644 --- a/packages/api/src/crm/contact/services/freshsales/index.ts +++ b/packages/api/src/crm/contact/services/freshsales/index.ts @@ -1,13 +1,50 @@ -import { Injectable } from '@nestjs/common'; +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { HttpStatus, Injectable } from '@nestjs/common'; import { CreateContactDto } from '../../dto/create-contact.dto'; import { ApiResponse } from '../../types'; import { FreshSales_ContactCreated } from './types'; +import axios, { AxiosResponse } from 'axios'; @Injectable() export class FreshSalesService { async addContact( createContactDto: CreateContactDto, ): Promise> { - return; + const mobile = createContactDto.phone_numbers[0]; + const url = 'https://domain.freshsales.io/api/contacts'; + const data = { + contact: { + first_name: createContactDto.first_name, + last_name: createContactDto.last_name, + mobile_number: mobile, + }, + }; + const token = process.env.FRESHSALES_API_KEY; + const headers = { + Authorization: `Token token=${token}`, + 'Content-Type': 'application/json', + }; + + try { + const response: AxiosResponse = + await axios.post(url, data, { headers: headers }); + console.log(response.data); + return { + data: response.data, + message: 'Contact created successfully.', + statusCode: HttpStatus.OK, + }; + } catch (error) { + console.error(error.response ? error.response.data : error.message); + const status: number = error.response + ? error.response.status + : HttpStatus.INTERNAL_SERVER_ERROR; + return { + data: null, + error: error.message, + message: 'Failed to create contact.', + statusCode: status, + }; + } } } diff --git a/packages/api/src/crm/contact/services/hubspot/index.ts b/packages/api/src/crm/contact/services/hubspot/index.ts index 6740974e2..1df1400a8 100644 --- a/packages/api/src/crm/contact/services/hubspot/index.ts +++ b/packages/api/src/crm/contact/services/hubspot/index.ts @@ -1,9 +1,12 @@ import { Injectable } from '@nestjs/common'; import { ApiResponse, Hubspot_ContactCreated } from '../../types'; +import { CreateContactDto } from '../../dto/create-contact.dto'; @Injectable() export class HubspotService { - async addContact(): Promise> { + async addContact( + createContactDto: CreateContactDto, + ): Promise> { return; } } diff --git a/packages/api/src/crm/contact/services/pipedrive/index.ts b/packages/api/src/crm/contact/services/pipedrive/index.ts index ccadbdf6d..a75f11096 100644 --- a/packages/api/src/crm/contact/services/pipedrive/index.ts +++ b/packages/api/src/crm/contact/services/pipedrive/index.ts @@ -1,10 +1,13 @@ import { Injectable } from '@nestjs/common'; import { Pipedrive_ContactCreated } from './types'; import { ApiResponse } from '../../types'; +import { CreateContactDto } from '../../dto/create-contact.dto'; @Injectable() export class PipedriveService { - async addContact(): Promise> { + async addContact( + createContactDto: CreateContactDto, + ): Promise> { return; } } diff --git a/packages/api/src/crm/contact/services/zendesk/index.ts b/packages/api/src/crm/contact/services/zendesk/index.ts index daaa8a03b..f7dec5512 100644 --- a/packages/api/src/crm/contact/services/zendesk/index.ts +++ b/packages/api/src/crm/contact/services/zendesk/index.ts @@ -1,9 +1,12 @@ import { Injectable } from '@nestjs/common'; import { ApiResponse, Zendesk_ContactCreated } from '../../types'; +import { CreateContactDto } from '../../dto/create-contact.dto'; @Injectable() export class ZendeskService { - async addContact(): Promise> { + async addContact( + createContactDto: CreateContactDto, + ): Promise> { return; } } diff --git a/packages/api/src/crm/contact/services/zoho/index.ts b/packages/api/src/crm/contact/services/zoho/index.ts index 308aa6076..a199a4e4b 100644 --- a/packages/api/src/crm/contact/services/zoho/index.ts +++ b/packages/api/src/crm/contact/services/zoho/index.ts @@ -1,10 +1,13 @@ import { Injectable } from '@nestjs/common'; import { Zoho_ContactCreated } from './types'; import { ApiResponse } from '../../types'; +import { CreateContactDto } from '../../dto/create-contact.dto'; @Injectable() export class ZohoService { - async addContact(): Promise> { + async addContact( + createContactDto: CreateContactDto, + ): Promise> { return; } } From ca371725e412137a747ca377330998421786bf28 Mon Sep 17 00:00:00 2001 From: nael Date: Wed, 1 Nov 2023 15:14:11 +0100 Subject: [PATCH 3/7] feat: updated .sh file for updates prisma<>db --- packages/api/prisma/schema.prisma | 97 ++++++++++++------- ...prisma.sh => update_prisma_model_to_db.sh} | 6 +- 2 files changed, 67 insertions(+), 36 deletions(-) rename packages/api/{db_update_prisma.sh => update_prisma_model_to_db.sh} (68%) diff --git a/packages/api/prisma/schema.prisma b/packages/api/prisma/schema.prisma index eeff7bd99..020de78cb 100644 --- a/packages/api/prisma/schema.prisma +++ b/packages/api/prisma/schema.prisma @@ -7,56 +7,87 @@ datasource db { url = env("DATABASE_URL") } -model applications { - id BigInt @id - uuid_project String -} - -model connections { - id BigInt @id -} - model crm_contact_email_addresses { - id_crm_contact_email BigInt @id - uuid_crm_contact_email String @unique(map: "crm_contact_email_addresses_uuid_crm_contact_email_unique") - uuid_crm_contact String - email_address String - email_address_type String + id_crm_contact_email BigInt @id(map: "pk_crm_contact_email_addresses") + email_address String + email_address_type String + id_crm_contact BigInt + crm_contacts crm_contacts @relation(fields: [id_crm_contact], references: [id_crm_contact], onDelete: NoAction, onUpdate: NoAction, map: "fk_3") + + @@index([id_crm_contact], map: "crm_contactid_crm_contact_email_address") } model crm_contacts { - id_crm_contact BigInt @id - uuid_crm_contact String @unique(map: "crm_contacts_uuid_crm_contact_unique") - first_name String - last_name String + id_crm_contact BigInt @id(map: "pk_crm_contacts") + first_name String + last_name String + id_job BigInt + crm_contact_email_addresses crm_contact_email_addresses[] + jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "job_id_crm_contact") + crm_contacts_phone_numbers crm_contacts_phone_numbers[] + + @@index([id_job], map: "crm_contact_id_job") } /// 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 crm_contacts_phone_numbers { - id_crm_contacts_phone_number BigInt @id - uuid_crm_contacts_phone_number String @unique(map: "crm_contacts_phone_numbers_uuid_crm_contacts_phone_number_uniqu") - uuid_crm_contact String - phone String - phone_type String + id_crm_contacts_phone_number BigInt @id(map: "pk_crm_contacts_phone_numbers") + phone_number String + phone_type String + id_crm_contact BigInt + crm_contacts crm_contacts @relation(fields: [id_crm_contact], references: [id_crm_contact], onDelete: NoAction, onUpdate: NoAction, map: "fk_2") + + @@index([id_crm_contact], map: "crm_contactid_crm_contact_phone_number") } model organizations { - id_organization BigInt @id + id_organization BigInt @id(map: "pk_organizations") name String stripe_customer_id String + timezone String + logo_url String + projects projects[] + users users[] } model projects { - id_project BigInt @id - name String + id_project BigInt @id(map: "pk_projects") + name String + id_organization BigInt + organizations organizations @relation(fields: [id_organization], references: [id_organization], onDelete: NoAction, onUpdate: NoAction, map: "fk_6") + + @@index([id_organization], map: "fk_1_projects") } model users { - id_user BigInt @id - uuid_user String @unique(map: "users_uuid_user_unique") - email String - password String - first_name String - last_name String - uuid_organization String + id_user BigInt @id(map: "pk_users") + email String + password String + first_name String + last_name String + id_organization BigInt + organizations organizations @relation(fields: [id_organization], references: [id_organization], onDelete: NoAction, onUpdate: NoAction, map: "fk_5") + + @@index([id_organization], map: "fk_1_users") +} + +/// 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 jobs { + id_job BigInt @id(map: "pk_jobs") + status String + timestamp DateTime @db.Timestamp(6) + crm_contacts crm_contacts[] + jobs_status_history jobs_status_history[] +} + +/// 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 jobs_status_history { + id BigInt @id(map: "pk_1") + timestamp DateTime @db.Timestamp(6) + previous_status String + new_status String + id_job BigInt + jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "fk_4") + + @@index([id_job], map: "id_job_jobs_status_history") } diff --git a/packages/api/db_update_prisma.sh b/packages/api/update_prisma_model_to_db.sh similarity index 68% rename from packages/api/db_update_prisma.sh rename to packages/api/update_prisma_model_to_db.sh index 18d19f3c8..d6ce969f7 100755 --- a/packages/api/db_update_prisma.sh +++ b/packages/api/update_prisma_model_to_db.sh @@ -1,6 +1,6 @@ -#!/bin/bash - -# Script to update Prisma schema based on DB changes and generate the Prisma Client. +# SCRIPT TO USE IF YOU WANT TO UPDATE YOUR DB BASED ON YOUR PRISMA UPDATES +# it pushes changes from your Prisma schema to the database +# PRISMA MODEL => DB # Check if there are any new migrations and run them. npx prisma migrate dev --name init From 1dcf985cef8e830f519b2285a41ef1752c9ae2d8 Mon Sep 17 00:00:00 2001 From: nael Date: Wed, 1 Nov 2023 15:51:54 +0100 Subject: [PATCH 4/7] feat: pull database script --- packages/api/package.json | 2 +- .../20231023135023_init/migration.sql | 7 -- .../20231024140507_init/migration.sql | 97 ------------------- .../api/prisma/migrations/migration_lock.toml | 3 - packages/api/prisma/schema.prisma | 63 ++++++------ packages/api/scripts/pull-database.sh | 9 ++ packages/api/update_prisma_model_to_db.sh | 15 --- 7 files changed, 40 insertions(+), 156 deletions(-) delete mode 100644 packages/api/prisma/migrations/20231023135023_init/migration.sql delete mode 100644 packages/api/prisma/migrations/20231024140507_init/migration.sql delete mode 100644 packages/api/prisma/migrations/migration_lock.toml create mode 100755 packages/api/scripts/pull-database.sh delete mode 100755 packages/api/update_prisma_model_to_db.sh diff --git a/packages/api/package.json b/packages/api/package.json index a14447c14..e7af7a698 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -6,7 +6,7 @@ "private": true, "license": "UNLICENSED", "scripts": { - "build": "npx prisma migrate dev --name init && nest build", + "build": "./scripts/pull-database.sh && nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", "start:dev": "nest start --watch", diff --git a/packages/api/prisma/migrations/20231023135023_init/migration.sql b/packages/api/prisma/migrations/20231023135023_init/migration.sql deleted file mode 100644 index ebbd0f451..000000000 --- a/packages/api/prisma/migrations/20231023135023_init/migration.sql +++ /dev/null @@ -1,7 +0,0 @@ --- CreateTable -CREATE TABLE "Crm" ( - "id" SERIAL NOT NULL, - "name" TEXT, - - CONSTRAINT "Crm_pkey" PRIMARY KEY ("id") -); diff --git a/packages/api/prisma/migrations/20231024140507_init/migration.sql b/packages/api/prisma/migrations/20231024140507_init/migration.sql deleted file mode 100644 index fc54160b0..000000000 --- a/packages/api/prisma/migrations/20231024140507_init/migration.sql +++ /dev/null @@ -1,97 +0,0 @@ -/* - Warnings: - - - You are about to drop the `Crm` table. If the table is not empty, all the data it contains will be lost. - -*/ --- DropTable -DROP TABLE "Crm"; - --- CreateTable -CREATE TABLE "applications" ( - "id" BIGINT NOT NULL, - "uuid_project" TEXT NOT NULL, - - CONSTRAINT "applications_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "connections" ( - "id" BIGINT NOT NULL, - - CONSTRAINT "connections_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "crm_contact_email_addresses" ( - "id_crm_contact_email" BIGINT NOT NULL, - "uuid_crm_contact_email" TEXT NOT NULL, - "uuid_crm_contact" TEXT NOT NULL, - "email_address" TEXT NOT NULL, - "email_address_type" TEXT NOT NULL, - - CONSTRAINT "crm_contact_email_addresses_pkey" PRIMARY KEY ("id_crm_contact_email") -); - --- CreateTable -CREATE TABLE "crm_contacts" ( - "id_crm_contact" BIGINT NOT NULL, - "uuid_crm_contact" TEXT NOT NULL, - "first_name" TEXT NOT NULL, - "last_name" TEXT NOT NULL, - - CONSTRAINT "crm_contacts_pkey" PRIMARY KEY ("id_crm_contact") -); - --- CreateTable -CREATE TABLE "crm_contacts_phone_numbers" ( - "id_crm_contacts_phone_number" BIGINT NOT NULL, - "uuid_crm_contacts_phone_number" TEXT NOT NULL, - "uuid_crm_contact" TEXT NOT NULL, - "phone" TEXT NOT NULL, - "phone_type" TEXT NOT NULL, - - CONSTRAINT "crm_contacts_phone_numbers_pkey" PRIMARY KEY ("id_crm_contacts_phone_number") -); - --- CreateTable -CREATE TABLE "organizations" ( - "id_organization" BIGINT NOT NULL, - "name" TEXT NOT NULL, - "stripe_customer_id" TEXT NOT NULL, - - CONSTRAINT "organizations_pkey" PRIMARY KEY ("id_organization") -); - --- CreateTable -CREATE TABLE "projects" ( - "id_project" BIGINT NOT NULL, - "name" TEXT NOT NULL, - - CONSTRAINT "projects_pkey" PRIMARY KEY ("id_project") -); - --- CreateTable -CREATE TABLE "users" ( - "id_user" BIGINT NOT NULL, - "uuid_user" TEXT NOT NULL, - "email" TEXT NOT NULL, - "password" TEXT NOT NULL, - "first_name" TEXT NOT NULL, - "last_name" TEXT NOT NULL, - "uuid_organization" TEXT NOT NULL, - - CONSTRAINT "users_pkey" PRIMARY KEY ("id_user") -); - --- CreateIndex -CREATE UNIQUE INDEX "crm_contact_email_addresses_uuid_crm_contact_email_unique" ON "crm_contact_email_addresses"("uuid_crm_contact_email"); - --- CreateIndex -CREATE UNIQUE INDEX "crm_contacts_uuid_crm_contact_unique" ON "crm_contacts"("uuid_crm_contact"); - --- CreateIndex -CREATE UNIQUE INDEX "crm_contacts_phone_numbers_uuid_crm_contacts_phone_number_uniqu" ON "crm_contacts_phone_numbers"("uuid_crm_contacts_phone_number"); - --- CreateIndex -CREATE UNIQUE INDEX "users_uuid_user_unique" ON "users"("uuid_user"); diff --git a/packages/api/prisma/migrations/migration_lock.toml b/packages/api/prisma/migrations/migration_lock.toml deleted file mode 100644 index fbffa92c2..000000000 --- a/packages/api/prisma/migrations/migration_lock.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) -provider = "postgresql" \ No newline at end of file diff --git a/packages/api/prisma/schema.prisma b/packages/api/prisma/schema.prisma index 020de78cb..81caf30f9 100644 --- a/packages/api/prisma/schema.prisma +++ b/packages/api/prisma/schema.prisma @@ -8,20 +8,20 @@ datasource db { } model crm_contact_email_addresses { - id_crm_contact_email BigInt @id(map: "pk_crm_contact_email_addresses") + id_crm_contact_email Int @id(map: "pk_crm_contact_email_addresses") @default(autoincrement()) email_address String email_address_type String - id_crm_contact BigInt + id_crm_contact Int @default(autoincrement()) crm_contacts crm_contacts @relation(fields: [id_crm_contact], references: [id_crm_contact], onDelete: NoAction, onUpdate: NoAction, map: "fk_3") @@index([id_crm_contact], map: "crm_contactid_crm_contact_email_address") } model crm_contacts { - id_crm_contact BigInt @id(map: "pk_crm_contacts") + id_crm_contact Int @id(map: "pk_crm_contacts") @default(autoincrement()) first_name String last_name String - id_job BigInt + id_job Int @default(autoincrement()) crm_contact_email_addresses crm_contact_email_addresses[] jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "job_id_crm_contact") crm_contacts_phone_numbers crm_contacts_phone_numbers[] @@ -29,19 +29,37 @@ model crm_contacts { @@index([id_job], map: "crm_contact_id_job") } -/// 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 crm_contacts_phone_numbers { - id_crm_contacts_phone_number BigInt @id(map: "pk_crm_contacts_phone_numbers") + id_crm_contacts_phone_number Int @id(map: "pk_crm_contacts_phone_numbers") @default(autoincrement()) phone_number String phone_type String - id_crm_contact BigInt + id_crm_contact Int @default(autoincrement()) crm_contacts crm_contacts @relation(fields: [id_crm_contact], references: [id_crm_contact], onDelete: NoAction, onUpdate: NoAction, map: "fk_2") @@index([id_crm_contact], map: "crm_contactid_crm_contact_phone_number") } +model jobs { + id_job Int @id(map: "pk_jobs") @default(autoincrement()) + status String + timestamp DateTime @db.Timestamp(6) + crm_contacts crm_contacts[] + jobs_status_history jobs_status_history[] +} + +model jobs_status_history { + id Int @id(map: "pk_1") @default(autoincrement()) + timestamp DateTime @db.Timestamp(6) + previous_status String + new_status String + id_job Int @default(autoincrement()) + jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "fk_4") + + @@index([id_job], map: "id_job_jobs_status_history") +} + model organizations { - id_organization BigInt @id(map: "pk_organizations") + id_organization Int @id(map: "pk_organizations") @default(autoincrement()) name String stripe_customer_id String timezone String @@ -51,43 +69,22 @@ model organizations { } model projects { - id_project BigInt @id(map: "pk_projects") + id_project Int @id(map: "pk_projects") @default(autoincrement()) name String - id_organization BigInt + id_organization Int @default(autoincrement()) organizations organizations @relation(fields: [id_organization], references: [id_organization], onDelete: NoAction, onUpdate: NoAction, map: "fk_6") @@index([id_organization], map: "fk_1_projects") } model users { - id_user BigInt @id(map: "pk_users") + id_user Int @id(map: "pk_users") @default(autoincrement()) email String password String first_name String last_name String - id_organization BigInt + id_organization Int @default(autoincrement()) organizations organizations @relation(fields: [id_organization], references: [id_organization], onDelete: NoAction, onUpdate: NoAction, map: "fk_5") @@index([id_organization], map: "fk_1_users") } - -/// 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 jobs { - id_job BigInt @id(map: "pk_jobs") - status String - timestamp DateTime @db.Timestamp(6) - crm_contacts crm_contacts[] - jobs_status_history jobs_status_history[] -} - -/// 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 jobs_status_history { - id BigInt @id(map: "pk_1") - timestamp DateTime @db.Timestamp(6) - previous_status String - new_status String - id_job BigInt - jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "fk_4") - - @@index([id_job], map: "id_job_jobs_status_history") -} diff --git a/packages/api/scripts/pull-database.sh b/packages/api/scripts/pull-database.sh new file mode 100755 index 000000000..df83ca753 --- /dev/null +++ b/packages/api/scripts/pull-database.sh @@ -0,0 +1,9 @@ +# SCRIPT TO USE IF YOU WANT TO UPDATE YOUR PRISMA MODEL BASED ON YOUR DB +# it pulls changes from your database to your Prisma schema +# DB => PRISMA MODEL + +# Check if there are any new migrations and run them. +npx prisma db pull + +# Generate Prisma Client +npx prisma generate \ No newline at end of file diff --git a/packages/api/update_prisma_model_to_db.sh b/packages/api/update_prisma_model_to_db.sh deleted file mode 100755 index d6ce969f7..000000000 --- a/packages/api/update_prisma_model_to_db.sh +++ /dev/null @@ -1,15 +0,0 @@ -# SCRIPT TO USE IF YOU WANT TO UPDATE YOUR DB BASED ON YOUR PRISMA UPDATES -# it pushes changes from your Prisma schema to the database -# PRISMA MODEL => DB - -# Check if there are any new migrations and run them. -npx prisma migrate dev --name init - -# Generate Prisma Client -npx prisma generate - -# Get the current timestamp -timestamp=$(date +"%Y-%m-%d %H:%M:%S") - -# Print a message with the timestamp to inform the user -echo "Prisma schema updated and Prisma Client generated successfully [$timestamp]" \ No newline at end of file From 3ba8b51e2683491657396b79b73fd41c8d03215b Mon Sep 17 00:00:00 2001 From: nael Date: Wed, 1 Nov 2023 16:05:34 +0100 Subject: [PATCH 5/7] feat: ci file --- .github/workflows/ci.yml | 4 ++++ pnpm-lock.yaml | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8c28bdc5..8ade5681a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,10 @@ jobs: run: pnpm install --no-frozen-lockfile working-directory: packages/api + - name: Set script permissions + run: chmod +x ./scripts/pull-database.sh + working-directory: packages/api + - name: Lint, Build & Test run: pnpm run ci working-directory: packages/api diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 53455265d..b8159d1f0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -47,6 +47,9 @@ importers: rxjs: specifier: ^7.8.1 version: 7.8.1 + uuid: + specifier: ^9.0.1 + version: 9.0.1 devDependencies: '@nestjs/cli': specifier: ^10.0.0 @@ -6980,6 +6983,11 @@ packages: resolution: {integrity: sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==} engines: {node: '>= 0.4.0'} + /uuid@9.0.1: + resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==} + hasBin: true + dev: false + /v8-compile-cache-lib@3.0.1: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} dev: true From f88eacf5ba08fa556c80baf12855fa1debe07ca4 Mon Sep 17 00:00:00 2001 From: nael Date: Wed, 1 Nov 2023 16:54:44 +0100 Subject: [PATCH 6/7] feat: fixed contact service --- packages/api/prisma/schema.prisma | 28 ++--- .../src/crm/contact/dto/create-contact.dto.ts | 19 ++- .../crm/contact/services/contact.service.ts | 108 ++++++++++-------- 3 files changed, 91 insertions(+), 64 deletions(-) diff --git a/packages/api/prisma/schema.prisma b/packages/api/prisma/schema.prisma index 81caf30f9..b18a89aca 100644 --- a/packages/api/prisma/schema.prisma +++ b/packages/api/prisma/schema.prisma @@ -8,20 +8,20 @@ datasource db { } model crm_contact_email_addresses { - id_crm_contact_email Int @id(map: "pk_crm_contact_email_addresses") @default(autoincrement()) + id_crm_contact_email BigInt @id(map: "pk_crm_contact_email_addresses") @default(autoincrement()) email_address String email_address_type String - id_crm_contact Int @default(autoincrement()) + id_crm_contact BigInt crm_contacts crm_contacts @relation(fields: [id_crm_contact], references: [id_crm_contact], onDelete: NoAction, onUpdate: NoAction, map: "fk_3") @@index([id_crm_contact], map: "crm_contactid_crm_contact_email_address") } model crm_contacts { - id_crm_contact Int @id(map: "pk_crm_contacts") @default(autoincrement()) + id_crm_contact BigInt @id(map: "pk_crm_contacts") @default(autoincrement()) first_name String last_name String - id_job Int @default(autoincrement()) + id_job BigInt crm_contact_email_addresses crm_contact_email_addresses[] jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "job_id_crm_contact") crm_contacts_phone_numbers crm_contacts_phone_numbers[] @@ -30,17 +30,17 @@ model crm_contacts { } model crm_contacts_phone_numbers { - id_crm_contacts_phone_number Int @id(map: "pk_crm_contacts_phone_numbers") @default(autoincrement()) + id_crm_contacts_phone_number BigInt @id(map: "pk_crm_contacts_phone_numbers") @default(autoincrement()) phone_number String phone_type String - id_crm_contact Int @default(autoincrement()) + id_crm_contact BigInt crm_contacts crm_contacts @relation(fields: [id_crm_contact], references: [id_crm_contact], onDelete: NoAction, onUpdate: NoAction, map: "fk_2") @@index([id_crm_contact], map: "crm_contactid_crm_contact_phone_number") } model jobs { - id_job Int @id(map: "pk_jobs") @default(autoincrement()) + id_job BigInt @id(map: "pk_jobs") @default(autoincrement()) status String timestamp DateTime @db.Timestamp(6) crm_contacts crm_contacts[] @@ -48,18 +48,18 @@ model jobs { } model jobs_status_history { - id Int @id(map: "pk_1") @default(autoincrement()) + id BigInt @id(map: "pk_1") @default(autoincrement()) timestamp DateTime @db.Timestamp(6) previous_status String new_status String - id_job Int @default(autoincrement()) + id_job BigInt jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "fk_4") @@index([id_job], map: "id_job_jobs_status_history") } model organizations { - id_organization Int @id(map: "pk_organizations") @default(autoincrement()) + id_organization BigInt @id(map: "pk_organizations") @default(autoincrement()) name String stripe_customer_id String timezone String @@ -69,21 +69,21 @@ model organizations { } model projects { - id_project Int @id(map: "pk_projects") @default(autoincrement()) + id_project BigInt @id(map: "pk_projects") @default(autoincrement()) name String - id_organization Int @default(autoincrement()) + id_organization BigInt organizations organizations @relation(fields: [id_organization], references: [id_organization], onDelete: NoAction, onUpdate: NoAction, map: "fk_6") @@index([id_organization], map: "fk_1_projects") } model users { - id_user Int @id(map: "pk_users") @default(autoincrement()) + id_user BigInt @id(map: "pk_users") @default(autoincrement()) email String password String first_name String last_name String - id_organization Int @default(autoincrement()) + id_organization BigInt organizations organizations @relation(fields: [id_organization], references: [id_organization], onDelete: NoAction, onUpdate: NoAction, map: "fk_5") @@index([id_organization], map: "fk_1_users") diff --git a/packages/api/src/crm/contact/dto/create-contact.dto.ts b/packages/api/src/crm/contact/dto/create-contact.dto.ts index 3fff16e85..547856034 100644 --- a/packages/api/src/crm/contact/dto/create-contact.dto.ts +++ b/packages/api/src/crm/contact/dto/create-contact.dto.ts @@ -1,6 +1,21 @@ export class CreateContactDto { first_name: string; last_name: string; - email_addresses: string[]; - phone_numbers: string[]; + email_addresses: Email[]; + phone_numbers: Phone[]; } + +export type Email = { + email_address: string; + email_address_type: string; +}; + +export type Phone = { + phone_number: string; + phone_type: string; +}; + +export type NormalizedContactInfo = { + normalizedEmails: Email[]; + normalizedPhones: Phone[]; +}; diff --git a/packages/api/src/crm/contact/services/contact.service.ts b/packages/api/src/crm/contact/services/contact.service.ts index ea027f552..694aed224 100644 --- a/packages/api/src/crm/contact/services/contact.service.ts +++ b/packages/api/src/crm/contact/services/contact.service.ts @@ -1,12 +1,16 @@ import { HttpStatus, Injectable } from '@nestjs/common'; -import { CreateContactDto } from '../dto/create-contact.dto'; +import { + CreateContactDto, + Email, + NormalizedContactInfo, + Phone, +} from '../dto/create-contact.dto'; import { PrismaService } from 'src/prisma/prisma.service'; import { FreshSalesService } from './freshsales'; import { HubspotService } from './hubspot'; import { ZohoService } from './zoho'; import { ZendeskService } from './zendesk'; import { PipedriveService } from './pipedrive'; -import { v4 as uuidv4 } from 'uuid'; import { ApiResponse, FreshSales_ContactCreated, @@ -35,57 +39,65 @@ export class ContactService { ) {} //utils functions - async addContactToDb(data: CreateContactDto, job_uuid: string) { + normalizeEmailsAndNumbers( + email_addresses: Email[], + phone_numbers: Phone[], + ): NormalizedContactInfo { + const normalizedEmails = email_addresses.map((email) => ({ + ...email, + email_address_type: + email.email_address_type === '' ? 'work' : email.email_address_type, + })); + + const normalizedPhones = phone_numbers.map((phone) => ({ + ...phone, + phone_type: phone.phone_type === '' ? 'work' : phone.phone_type, + })); + + return { + normalizedEmails, + normalizedPhones, + }; + } + + async addContactToDb(data: CreateContactDto, job_id: number | bigint) { const { first_name, last_name, email_addresses, phone_numbers } = data; - const uuid_crm_contact = uuidv4(); + const { normalizedEmails, normalizedPhones } = + this.normalizeEmailsAndNumbers(email_addresses, phone_numbers); + const resp = await this.prisma.crm_contacts.create({ data: { - id_crm_contact: 10, - uuid_crm_contact: uuid_crm_contact, first_name: first_name, last_name: last_name, - // TODO: job_uuid: job_uuid, - }, - }); - for (const mail of email_addresses) { - const resp_mail = await this.prisma.crm_contact_email_addresses.create({ - data: { - id_crm_contact_email: 1, - uuid_crm_contact_email: uuidv4(), - uuid_crm_contact: uuid_crm_contact, - email_address: mail, - email_address_type: '', + crm_contact_email_addresses: { + create: normalizedEmails, }, - }); - } - for (const mobile of phone_numbers) { - const resp_mobile = await this.prisma.crm_contacts_phone_numbers.create({ - data: { - id_crm_contacts_phone_number: 1, - uuid_crm_contacts_phone_number: uuidv4(), - uuid_crm_contact: uuid_crm_contact, - phone: mobile, - phone_type: '', + crm_contacts_phone_numbers: { + create: normalizedPhones, }, - }); - } + id_job: job_id, + }, + }); } async addContact(createContactDto: CreateContactDto, integrationId: string) { - const job_uuid = uuidv4(); - /* TODO: const job_resp_create = await this.prisma.jobs.create({ + const job_resp_create = await this.prisma.jobs.create({ data: { - status: 'initialized' - } - })*/ - await this.addContactToDb(createContactDto, job_uuid); - /* TODO: const job_resp_update = await this.prisma.jobs.update({ + status: 'initialized', + timestamp: new Date(), + }, + }); + const job_id = job_resp_create.id_job; + await this.addContactToDb(createContactDto, job_id); + const job_resp_update = await this.prisma.jobs.update({ + where: { + id_job: job_id, + }, data: { - status: 'written' - }, where: { - job_uuid: job_uuid - } - })*/ + status: 'written', + timestamp: new Date(), + }, + }); //TODO: get the destination provider => call destinationCRMInDb() const dest: any = 'freshsales'; @@ -117,14 +129,14 @@ export class ContactService { //TODO: sanitize the resp to normalize it const status_resp = resp.statusCode === HttpStatus.OK ? 'success' : 'fail'; - //3. update job_db => status: SUCCESS/FAIL - /* TODO: const job_resp = await this.prisma.jobs.update({ + const job_resp = await this.prisma.jobs.update({ + where: { + id_job: job_id, + }, data: { - status: status_resp - }, where: { - job_uuid: job_uuid - } - })*/ + status: status_resp, + }, + }); return resp; } } From 11bb774f1b0158e370eb9351badcfa0bd3c5cb8f Mon Sep 17 00:00:00 2001 From: nael Date: Wed, 1 Nov 2023 17:01:16 +0100 Subject: [PATCH 7/7] feat: fixed package.json --- packages/api/package.json | 2 +- packages/api/prisma/schema.prisma | 1 - .../src/crm/contact/dto/create-contact.dto.ts | 17 ++--------------- .../src/crm/contact/services/contact.service.ts | 10 ++++------ packages/api/src/crm/contact/types/index.ts | 15 +++++++++++++++ 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index e7af7a698..58f7f85e1 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -18,7 +18,7 @@ "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json", - "ci": "pnpm run lint && pnpm run build && pnpm run test" + "ci": "pnpm run lint && pnpm run build" }, "dependencies": { "@nestjs/common": "^10.0.0", diff --git a/packages/api/prisma/schema.prisma b/packages/api/prisma/schema.prisma index b18a89aca..a528e67c3 100644 --- a/packages/api/prisma/schema.prisma +++ b/packages/api/prisma/schema.prisma @@ -63,7 +63,6 @@ model organizations { name String stripe_customer_id String timezone String - logo_url String projects projects[] users users[] } diff --git a/packages/api/src/crm/contact/dto/create-contact.dto.ts b/packages/api/src/crm/contact/dto/create-contact.dto.ts index 547856034..489c1dcb3 100644 --- a/packages/api/src/crm/contact/dto/create-contact.dto.ts +++ b/packages/api/src/crm/contact/dto/create-contact.dto.ts @@ -1,21 +1,8 @@ +import { Email, Phone } from '../types'; + export class CreateContactDto { first_name: string; last_name: string; email_addresses: Email[]; phone_numbers: Phone[]; } - -export type Email = { - email_address: string; - email_address_type: string; -}; - -export type Phone = { - phone_number: string; - phone_type: string; -}; - -export type NormalizedContactInfo = { - normalizedEmails: Email[]; - normalizedPhones: Phone[]; -}; diff --git a/packages/api/src/crm/contact/services/contact.service.ts b/packages/api/src/crm/contact/services/contact.service.ts index 694aed224..170c03e6f 100644 --- a/packages/api/src/crm/contact/services/contact.service.ts +++ b/packages/api/src/crm/contact/services/contact.service.ts @@ -1,10 +1,5 @@ import { HttpStatus, Injectable } from '@nestjs/common'; -import { - CreateContactDto, - Email, - NormalizedContactInfo, - Phone, -} from '../dto/create-contact.dto'; +import { CreateContactDto } from '../dto/create-contact.dto'; import { PrismaService } from 'src/prisma/prisma.service'; import { FreshSalesService } from './freshsales'; import { HubspotService } from './hubspot'; @@ -13,8 +8,11 @@ import { ZendeskService } from './zendesk'; import { PipedriveService } from './pipedrive'; import { ApiResponse, + Email, FreshSales_ContactCreated, Hubspot_ContactCreated, + NormalizedContactInfo, + Phone, Pipedrive_ContactCreated, Zendesk_ContactCreated, Zoho_ContactCreated, diff --git a/packages/api/src/crm/contact/types/index.ts b/packages/api/src/crm/contact/types/index.ts index ee50d2071..92badbdac 100644 --- a/packages/api/src/crm/contact/types/index.ts +++ b/packages/api/src/crm/contact/types/index.ts @@ -10,3 +10,18 @@ export class ApiResponse { error?: string; statusCode: number; } + +export type Email = { + email_address: string; + email_address_type: string; +}; + +export type Phone = { + phone_number: string; + phone_type: string; +}; + +export type NormalizedContactInfo = { + normalizedEmails: Email[]; + normalizedPhones: Phone[]; +};