Skip to content

Commit

Permalink
Merge branch 'feat/update-major-sync'
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Dec 8, 2023
2 parents ae19552 + d6df0a6 commit 47be24c
Show file tree
Hide file tree
Showing 30 changed files with 474 additions and 250 deletions.
2 changes: 1 addition & 1 deletion apps/frontend-snippet/src/hooks/queries/useLinkedUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const useLinkedUser = (id: string) => {
return useQuery({
queryKey: ['linked-users', id],
queryFn: async (): Promise<LinkedUser> => {
const response = await fetch(`${config.API_URL}/linked-users?id=${id}`);
const response = await fetch(`${config.API_URL}/linked-users/single?id=${id}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const useUniqueMagicLink = (id: string) => {
return useQuery({
queryKey: ['magic-link', id],
queryFn: async (): Promise<MagicLink> => {
const response = await fetch(`${config.API_URL}/magic-link?id=${id}`);
const response = await fetch(`${config.API_URL}/magic-link/single?id=${id}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
Expand Down
4 changes: 3 additions & 1 deletion apps/frontend-snippet/src/lib/ProviderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ const ProviderModal = () => {
}
}, []);


const {data: magicLink} = useUniqueMagicLink(uniqueMagicLinkId);
const {data: linkedUser} = useLinkedUser(magicLink?.id_linked_user as string);



//TODO: externalize that in the backend => from
const { open, isReady } = useOAuth({
providerName: selectedProvider, // This will be set when a provider is clicked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import useDefineFieldMutation from "@/hooks/mutations/useDefineFieldMutation"
import useMapFieldMutation from "@/hooks/mutations/useMapFieldMutation"
import { useEffect, useState } from "react"
import useFieldMappings from "@/hooks/useFieldMappings"
import { useStandardObjects } from "@/hooks/useStandardObjects"
import useProviderProperties from "@/hooks/useProviderProperties"

export function FModal({ onClose }: {onClose: () => void}) {
Expand All @@ -50,11 +49,18 @@ export function FModal({ onClose }: {onClose: () => void}) {
const { mutate: mutateMapField } = useMapFieldMutation();
const { data: sourceCustomFields, error, isLoading } = useProviderProperties(linkedUserId,sourceProvider,standardModel);

const { data: sObjects } = useStandardObjects();

//const { data: sObjects } = useStandardObjects();
//TODO: get this from shared types
const sObjects = [
'contact',
'note',
'task'
]
useEffect(() => {
if (sourceCustomFields && !isLoading && !error) {
setSourceCustomFieldsData(sourceCustomFields);
if (sourceCustomFields && sourceCustomFields.data.length > 0 && !isLoading && !error) {
console.log("inside custom fields properties ");

setSourceCustomFieldsData(sourceCustomFields.data);
}
}, [sourceCustomFields, isLoading, error]);

Expand All @@ -72,7 +78,7 @@ export function FModal({ onClose }: {onClose: () => void}) {
const handleMapSubmit = (e: React.FormEvent) => {
e.preventDefault();
mutateMapField({
attributeId: attributeId,
attributeId: attributeId.trim(),
source_custom_field_id: sourceCustomFieldId,
source_provider: sourceProvider,
linked_user_id: linkedUserId,
Expand Down Expand Up @@ -109,7 +115,7 @@ export function FModal({ onClose }: {onClose: () => void}) {
<SelectGroup>
{sObjects && sObjects
.map(sObject => (
<SelectItem key={sObject.id_entity} value={sObject.ressource_owner_id}>{sObject.ressource_owner_id}</SelectItem>
<SelectItem key={sObject} value={sObject}>{sObject}</SelectItem>
))
}
</SelectGroup>
Expand Down Expand Up @@ -225,7 +231,7 @@ export function FModal({ onClose }: {onClose: () => void}) {
<SelectContent>
<SelectGroup>
{sourceCustomFieldsData.map(field => (
<SelectItem key={field.id} value={field.id}>{field.name}</SelectItem>
<SelectItem key={field.name} value={field.name}>{field.name}</SelectItem>
))}
</SelectGroup>
</SelectContent>
Expand Down
22 changes: 10 additions & 12 deletions apps/webapp/src/components/connections/ConnectionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ export default function ConnectionTable() {
const {uniqueLink} = useMagicLinkStore();

if (isLoading) {
console.log("loading connections..");
}

if (error) {
console.log("error connections..");
}
if (!connections) {
return <div className="flex flex-col items-center">
Connections not found....
<Skeleton className="w-[100px] h-[20px] rounded-md mt-10" />
</div>;
}
const linkedConnections = (filter: string) => connections.filter((connection) => connection.status == filter);

if (error) {
console.log("error connections..");
}

const linkedConnections = (filter: string) => connections?.filter((connection) => connection.status == filter);

const ts = connections?.map((connection) => ({
organisation: connection.id_project, // replace with actual mapping
Expand All @@ -58,7 +56,7 @@ export default function ConnectionTable() {
<CardTitle>Linked</CardTitle>
</CardHeader>
<CardContent>
<p className="text-4xl font-bold">{linkedConnections("0").length}</p>
<p className="text-4xl font-bold">{linkedConnections("0")?.length}</p>
</CardContent>

</Card>
Expand All @@ -67,15 +65,15 @@ export default function ConnectionTable() {
<CardTitle>Incomplete Link</CardTitle>
</CardHeader>
<CardContent>
<p className="text-4xl font-bold">{linkedConnections("1").length}</p>
<p className="text-4xl font-bold">{linkedConnections("1")?.length}</p>
</CardContent>
</Card>
<Card className="w-1/3">
<CardHeader>
<CardTitle>Relink Needed</CardTitle>
</CardHeader>
<CardContent>
<p className="text-4xl font-bold">{linkedConnections("2").length}</p>
<p className="text-4xl font-bold">{linkedConnections("2")?.length}</p>
</CardContent>

</Card>
Expand All @@ -102,7 +100,7 @@ export default function ConnectionTable() {
</div>
</div>
<DialogFooter>
<Button type="submit" onClick={() => window.open(`${config.FRONT_DOMAIN}/uniqueLink=${uniqueLink}`, '_blank')}>
<Button type="submit" onClick={() => window.open(`${config.FRONT_DOMAIN}/?uniqueLink=${uniqueLink}`, '_blank')}>
<p className="mr-2">Open Link</p>
<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3 2C2.44772 2 2 2.44772 2 3V12C2 12.5523 2.44772 13 3 13H12C12.5523 13 13 12.5523 13 12V8.5C13 8.22386 12.7761 8 12.5 8C12.2239 8 12 8.22386 12 8.5V12H3V3L6.5 3C6.77614 3 7 2.77614 7 2.5C7 2.22386 6.77614 2 6.5 2H3ZM12.8536 2.14645C12.9015 2.19439 12.9377 2.24964 12.9621 2.30861C12.9861 2.36669 12.9996 2.4303 13 2.497L13 2.5V2.50049V5.5C13 5.77614 12.7761 6 12.5 6C12.2239 6 12 5.77614 12 5.5V3.70711L6.85355 8.85355C6.65829 9.04882 6.34171 9.04882 6.14645 8.85355C5.95118 8.65829 5.95118 8.34171 6.14645 8.14645L11.2929 3H9.5C9.22386 3 9 2.77614 9 2.5C9 2.22386 9.22386 2 9.5 2H12.4999H12.5C12.5678 2 12.6324 2.01349 12.6914 2.03794C12.7504 2.06234 12.8056 2.09851 12.8536 2.14645Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg>
</Button>
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/components/jobs/JobsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { columns } from "./components/columns"
import { DataTable } from "../shared/data-table"
import useJobs from "@/hooks/useJobs";
import { DataTableLoading } from "../shared/data-table-loading";
import { jobs as Job } from "api";
import { events as Job } from "api";

export default function JobsTable() {
const { data: jobs, isLoading, error } = useJobs();
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/hooks/useJobs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from '@/utils/config';
import { useQuery } from '@tanstack/react-query';
import { jobs as Job } from 'api';
import { events as Job } from 'api';

const fetchJobs = async (): Promise<Job[]> => {
const response = await fetch(`${config.API_URL}/jobs`);
Expand Down
5 changes: 2 additions & 3 deletions apps/webapp/src/hooks/useProviderProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { getProviderVertical } from 'shared-types';
const useProviderProperties = (linkedUserId: string, providerId: string, standardObject: string) => {
return useQuery({
queryKey: ['providerProperties', linkedUserId, providerId, standardObject],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
queryFn: async (): Promise<Record<string, any>[]> => {
const response = await fetch(`${config.API_URL}/${getProviderVertical(providerId).toLowerCase()}/${standardObject.toLowerCase()}/properties?linkedUserId=${linkedUserId}&providerId=${providerId}`);
queryFn: async () => {
const response = await fetch(`${config.API_URL}/${getProviderVertical(providerId).toLowerCase()}/contact/properties?linkedUserId=${linkedUserId}&providerId=${providerId}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
Expand Down
3 changes: 1 addition & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
"pino-pretty": "^10.2.3",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"uuid": "^9.0.1",
"shared-types": "workspace:*"
"uuid": "^9.0.1"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
Expand Down
60 changes: 33 additions & 27 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,31 @@ model crm_contacts {
last_name String
created_at DateTime @db.Timestamp(6)
modified_at DateTime @db.Timestamp(6)
id_job String @db.Uuid
origin String
origin_id String
id_crm_user String? @db.Uuid
id_event String @db.Uuid
crm_addresses crm_addresses[]
crm_users crm_users? @relation(fields: [id_crm_user], references: [id_crm_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_23")
jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "job_id_crm_contact")
events events @relation(fields: [id_event], references: [id_event], onDelete: NoAction, onUpdate: NoAction, map: "job_id_crm_contact")
crm_email_addresses crm_email_addresses[]
crm_notes crm_notes[]
crm_phone_numbers crm_phone_numbers[]
@@index([id_job], map: "crm_contact_id_job")
@@index([id_event], map: "crm_contact_id_job")
@@index([id_crm_user], map: "fk_crm_contact_userid")
}

/// 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 String @id(map: "pk_jobs") @db.Uuid
status String
timestamp DateTime @default(now()) @db.Timestamp(6)
id_linked_user String @db.Uuid
crm_companies crm_companies[]
crm_contacts crm_contacts[]
linked_users linked_users @relation(fields: [id_linked_user], references: [id_linked_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_12")
jobs_status_history jobs_status_history[]
@@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 jobs_status_history {
id_jobs_status_history String @id(map: "pk_jobs_status_history") @db.Uuid
timestamp DateTime @default(now()) @db.Timestamp(6)
previous_status String
new_status String
id_job String @db.Uuid
jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "fk_4")
id_event String @db.Uuid
events events @relation(fields: [id_event], references: [id_event], onDelete: NoAction, onUpdate: NoAction, map: "fk_4")
@@index([id_job], map: "id_job_jobs_status_history")
@@index([id_event], map: "id_job_jobs_status_history")
}

model organizations {
Expand All @@ -76,6 +64,8 @@ model projects {
id_project String @id(map: "pk_projects") @db.Uuid
name String
id_organization String @db.Uuid
sync_mode String
pull_frequency BigInt?
api_keys api_keys[]
connections connections[]
linked_users linked_users[]
Expand Down Expand Up @@ -128,8 +118,8 @@ model linked_users {
alias String
id_project String @db.Uuid
connections connections[]
events events[]
invite_links invite_links[]
jobs jobs[]
projects projects @relation(fields: [id_project], references: [id_project], onDelete: NoAction, onUpdate: NoAction, map: "fk_10")
@@index([id_project], map: "fk_proectid_linked_users")
Expand Down Expand Up @@ -176,10 +166,10 @@ model crm_companies {
number_of_employees BigInt?
created_at DateTime @db.Timestamp(6)
modified_at DateTime @db.Timestamp(6)
id_job String @db.Uuid
id_crm_user String? @db.Uuid
id_event String @db.Uuid
crm_addresses crm_addresses[]
jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "fk_13")
events events @relation(fields: [id_event], references: [id_event], onDelete: NoAction, onUpdate: NoAction, map: "fk_13")
crm_users crm_users? @relation(fields: [id_crm_user], references: [id_crm_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_24")
crm_email_addresses crm_email_addresses[]
crm_engagements crm_engagements[]
Expand All @@ -188,7 +178,7 @@ model crm_companies {
crm_tasks crm_tasks[]
@@index([id_crm_user], map: "fk_crm_company_crm_userid")
@@index([id_job], map: "fk_crm_company_jobid")
@@index([id_event], map: "fk_crm_company_jobid")
}

/// 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
Expand Down Expand Up @@ -307,10 +297,10 @@ model attribute {
data_type String
remote_id String
source String
id_entity String @db.Uuid
id_entity String? @db.Uuid
scope String
id_consumer String? @db.Uuid
entity entity @relation(fields: [id_entity], references: [id_entity], onDelete: NoAction, onUpdate: NoAction, map: "fk_32")
entity entity? @relation(fields: [id_entity], references: [id_entity], onDelete: NoAction, onUpdate: NoAction, map: "fk_32")
value value[]
@@index([id_entity], map: "fk_attribute_entityid")
Expand All @@ -319,7 +309,7 @@ model attribute {
/// 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 entity {
id_entity String @id(map: "pk_entity") @db.Uuid
ressource_owner_id String
ressource_owner_id String @db.Uuid
attribute attribute[]
value value[]
}
Expand Down Expand Up @@ -380,3 +370,19 @@ model invite_links {
@@index([id_linked_user], map: "fk_invite_link_linkeduserid")
}

/// 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 events {
id_event String @id(map: "pk_jobs") @db.Uuid
status String
type String
direction String
timestamp DateTime @default(now()) @db.Timestamp(6)
id_linked_user String @db.Uuid
crm_companies crm_companies[]
crm_contacts crm_contacts[]
linked_users linked_users @relation(fields: [id_linked_user], references: [id_linked_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_12")
jobs_status_history jobs_status_history[]
@@index([id_linked_user], map: "fk_linkeduserid_projectid")
}
9 changes: 6 additions & 3 deletions packages/api/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ async function main() {
id_project: uuidv4(),
name: `Project ${index + 1}`,
id_organization: org.id_organization,
sync_mode: 'pool',
}));

await prisma.projects.createMany({
data: projectsData,
});

// Seed the `linked_users` table with 10 linked users
const linkedUsersData = Array.from({ length: 10 }).map((_, index) => ({
/*const linkedUsersData = Array.from({ length: 10 }).map((_, index) => ({
id_linked_user: uuidv4(),
linked_user_origin_id: `acme_origin_id_${uuidv4()}`,
alias: `Acme Inc`,
Expand Down Expand Up @@ -186,13 +187,15 @@ async function main() {
// Seed the `jobs` table with 20 jobs
const jobsData = Array.from({ length: 10 }).map((_, index) => ({
id_job: uuidv4(), // Generate a new UUID for each job
id_event: uuidv4(), // Generate a new UUID for each job
status: 'initialized', // Use whatever status is appropriate
type: 'pull',
direction: '0',
timestamp: new Date(),
id_linked_user: linkedUsersData[index].id_linked_user,
}));
const jobs = await prisma.jobs.createMany({
const jobs = await prisma.events.createMany({
data: jobsData,
skipDuplicates: true, // Set to true to ignore conflicts (optional)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CrmConnectionsService } from './crm/services/crm-connection.service';
import { LoggerService } from '@@core/logger/logger.service';
import { handleServiceError } from '@@core/utils/errors';
import { PrismaService } from '@@core/prisma/prisma.service';
import { ProviderVertical, getProviderVertical } from 'shared-types';
import { ProviderVertical, getProviderVertical } from '@@core/utils/types';
@Controller('connections')
export class ConnectionsController {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class HubspotConnectionService {
constructor(private prisma: PrismaService, private logger: LoggerService) {
this.logger.setContext(HubspotConnectionService.name);
}
async addLinkedUserAndProjectTest() {
/*async addLinkedUserAndProjectTest() {
const newOrganization = {
id_organization: uuidv4(),
name: 'New Organization',
Expand All @@ -34,6 +34,7 @@ export class HubspotConnectionService {
id_project: uuidv4(),
name: 'New Project',
id_organization: newOrganization.id_organization,
sync_mode: 'pool',
};
const data1 = await this.prisma.projects.create({
data: newProject,
Expand All @@ -51,7 +52,7 @@ export class HubspotConnectionService {
data: newLinkedUser,
});
this.logger.log('Added new linked_user ' + data);
}
}*/

async handleHubspotCallback(
linkedUserId: string,
Expand Down
Loading

0 comments on commit 47be24c

Please sign in to comment.