Skip to content

Commit

Permalink
Merge pull request #411 from mit-27/fix-backend-issues
Browse files Browse the repository at this point in the history
Fix backend issues
  • Loading branch information
naelob authored May 3, 2024
2 parents c574efe + cdd43a4 commit fd18b96
Show file tree
Hide file tree
Showing 84 changed files with 269 additions and 286 deletions.
2 changes: 1 addition & 1 deletion apps/client-ts/src/app/(Dashboard)/configuration/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default function Page() {
Add Field Mappings
</Button>
</DialogTrigger>
<DialogContent className="sm:w-[450px]">
<DialogContent className="sm:w-[450px] lg:max-w-screen-lg overflow-y-scroll max-h-screen">
<FModal onClose={handleClose}/>
</DialogContent>
</Dialog>
Expand Down
13 changes: 8 additions & 5 deletions apps/client-ts/src/components/Configuration/AddWebhook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ const formSchema = z.object({

const AddWebhook = () => {
const [open, setOpen] = useState(false);
const handleClose = () => {
setOpen(false);
};

const posthog = usePostHog()

const {idProject} = useProjectStore();
Expand All @@ -73,6 +71,11 @@ const AddWebhook = () => {
event: scopes[0]
},
})

const handleOpenChange = (openVal : boolean) => {
setOpen(openVal);
form.reset();
};

function onSubmit(values: z.infer<typeof formSchema>) {
console.log(values)
Expand All @@ -82,15 +85,15 @@ const AddWebhook = () => {
id_project: idProject,
scope: [values.event],
});
handleClose();
handleOpenChange(false);
posthog?.capture("webhook_created", {
id_project: idProject,
mode: config.DISTRIBUTION
})
}

return (
<Dialog open={open} onOpenChange={setOpen}>
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogTrigger asChild>
<Button
variant="outline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function FModal({ onClose }: {onClose: () => void}) {
}

return (
<Tabs defaultValue="define" className="w-[400px] mt-5">
<Tabs defaultValue="define" className="m-2" >
<TabsList className="grid w-full grid-cols-2">
<TabsTrigger value="define">Define Field</TabsTrigger>
<TabsTrigger value="map">Map Fields</TabsTrigger>
Expand Down
10 changes: 8 additions & 2 deletions apps/client-ts/src/components/Connection/AddConnectionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ const AddConnectionButton = ({
})

setIsGenerated(true);
form.reset()
}

const onClose = () => {
setShowNewLinkedUserDialog({open: false})
form.reset();
}

return (
Expand Down Expand Up @@ -190,7 +196,7 @@ const AddConnectionButton = ({
</DialogDescription>
</DialogHeader>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} >
<form onSubmit={form.handleSubmit(onSubmit)} onReset={() => onClose()} >
<div>
<div className="space-y-4 py-2 pb-4">
{!showNewLinkedUserDialog.import ?
Expand Down Expand Up @@ -250,7 +256,7 @@ const AddConnectionButton = ({
</div>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline" onClick={() => setShowNewLinkedUserDialog({open: false})}>
<Button variant="outline" type="reset">
Cancel
</Button>
</DialogClose>
Expand Down
2 changes: 1 addition & 1 deletion apps/client-ts/src/components/RootLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const RootLayout = ({children}:{children:React.ReactNode}) => {
</div>
</nav>

<main className="w-full pt-16">{children}</main>
<main className="w-full pt-16 overflow-y-scroll">{children}</main>

</div>
</>
Expand Down
10 changes: 8 additions & 2 deletions apps/client-ts/src/components/shared/team-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ export default function TeamSwitcher({ className ,projects}: TeamSwitcherProps)
id_user: profile!.id_user,
});
setShowNewDialog({open: false})
projectForm.reset();
}

const onClose = () => {
setShowNewDialog({open:false})
projectForm.reset();
}


Expand Down Expand Up @@ -209,7 +215,7 @@ export default function TeamSwitcher({ className ,projects}: TeamSwitcherProps)
</> :
<>
<Form {...projectForm}>
<form onSubmit={projectForm.handleSubmit(onProjectSubmit)} >
<form onSubmit={projectForm.handleSubmit(onProjectSubmit)} onReset={() => onClose()}>
<DialogHeader>
<DialogTitle>Create project</DialogTitle>
<DialogDescription>
Expand Down Expand Up @@ -242,7 +248,7 @@ export default function TeamSwitcher({ className ,projects}: TeamSwitcherProps)
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setShowNewDialog({open:false})}>
<Button variant="outline" type="reset">
Cancel
</Button>
<Button type="submit">Create</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const useUpdateConnectionStrategyMutation = () => {
}),
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${Cookies.get('access_token')}`,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import { ConnectionsStrategiesController } from './connections-strategies.contro
import { ConnectionsStrategiesService } from './connections-strategies.service';
import { ConfigService } from '@nestjs/config';
import { ValidateUserService } from '@@core/utils/services/validateUser.service';
import { EncryptionService } from '@@core/encryption/encryption.service';

@Module({
controllers: [ConnectionsStrategiesController],
providers: [
LoggerService,
EncryptionService,
PrismaService,
ConnectionsStrategiesService,
ConfigService,
ValidateUserService,
],
})
export class ConnectionsStrategiesModule {}
export class ConnectionsStrategiesModule { }
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EncryptionService } from '@@core/encryption/encryption.service';
import { PrismaService } from '@@core/prisma/prisma.service';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
Expand Down Expand Up @@ -27,6 +28,7 @@ export type RateLimit = {
export class ConnectionsStrategiesService {
constructor(
private prisma: PrismaService,
private crypto: EncryptionService,
private configService: ConfigService,
) { }

Expand Down Expand Up @@ -86,7 +88,7 @@ export class ConnectionsStrategiesService {
const value_ = await this.prisma.cs_values.create({

Check warning on line 88 in packages/api/src/@core/connections-strategies/connections-strategies.service.ts

View workflow job for this annotation

GitHub Actions / Build and Test (18.x)

'value_' is assigned a value but never used

Check warning on line 88 in packages/api/src/@core/connections-strategies/connections-strategies.service.ts

View workflow job for this annotation

GitHub Actions / Changeset

'value_' is assigned a value but never used
data: {
id_cs_value: uuidv4(),
value: value,
value: this.crypto.encrypt(value),
id_cs_attribute: attribute_.id_cs_attribute,
},
});
Expand Down Expand Up @@ -155,7 +157,7 @@ export class ConnectionsStrategiesService {
},
});
if (!value_) throw new Error('No value found !');
authValues.push(value_.value);
authValues.push(this.crypto.decrypt(value_.value));
}
return authValues;
}
Expand Down Expand Up @@ -335,6 +337,7 @@ export class ConnectionsStrategiesService {
values: string[],
) {
try {
console.log("In updateAPI xzx")
const cs = await this.prisma.connection_strategies.findFirst({
where: {
id_connection_strategy: id_cs,
Expand Down Expand Up @@ -373,12 +376,14 @@ export class ConnectionsStrategiesService {
id_cs_attribute: id_cs_attribute,
},
data: {
value: value,
value: this.crypto.encrypt(value),
},
});
}
return cs;
} catch (error) {
console.log("Error xzx")
console.log(error)
throw new Error('Update Failed');
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/company/services/attio/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class AttioCompanyMapper implements ICompanyMapper {
}

return {
remote_id: company.id.record_id,
name: company.values.name[0]?.value,
industry:
typeof company.values.categories[0]?.option === 'string'
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/company/services/hubspot/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class HubspotCompanyMapper implements ICompanyMapper {
}

return {
remote_id: company.id,
name: company.properties.name,
industry: company.properties.industry,
number_of_employees: 0, // Placeholder, as there's no direct mapping provided
Expand Down
7 changes: 5 additions & 2 deletions packages/api/src/crm/company/services/pipedrive/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ export class PipedriveCompanyMapper implements ICompanyMapper {
postal_code: company.address_postal_code,
};
}
res = { ...res, ...opts };
return res;
return {
remote_id: company.id,
...res,
...opts,
};
}
}
1 change: 1 addition & 0 deletions packages/api/src/crm/company/services/zendesk/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class ZendeskCompanyMapper implements ICompanyMapper {
}

return {
remote_id: String(company.id),
name: company.name,
email_addresses,
phone_numbers,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/company/services/zoho/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class ZohoCompanyMapper implements ICompanyMapper {
}

return {
remote_id: company.id,
name: company.Account_Name,
phone_numbers: [
{
Expand Down
23 changes: 9 additions & 14 deletions packages/api/src/crm/company/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class SyncService implements OnModuleInit {

//function used by sync worker which populate our crm_companies table
//its role is to fetch all companies 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 syncCompanies(user_id?: string) {
try {
Expand All @@ -83,12 +83,12 @@ export class SyncService implements OnModuleInit {
*/
const users = user_id
? [
await this.prisma.users.findUnique({
where: {
id_user: user_id,
},
}),
]
await this.prisma.users.findUnique({
where: {
id_user: user_id,
},
}),
]
: await this.prisma.users.findMany();
if (users && users.length > 0) {
for (const user of users) {
Expand Down Expand Up @@ -183,16 +183,12 @@ export class SyncService implements OnModuleInit {
customFieldMappings,
})) as UnifiedCompanyOutput[];

//TODO
const companyIds = sourceObject.map((company) =>
'id' in company ? String(company.id) : undefined,
);


//insert the data in the DB with the fieldMappings (value table)
const companies_data = await this.saveCompanysInDb(
linkedUserId,
unifiedObject,
companyIds,
integrationId,
sourceObject,
);
Expand Down Expand Up @@ -223,15 +219,14 @@ export class SyncService implements OnModuleInit {
async saveCompanysInDb(
linkedUserId: string,
companies: UnifiedCompanyOutput[],
originIds: string[],
originSource: string,
remote_data: Record<string, any>[],
): Promise<CrmCompany[]> {
try {
let companies_results: CrmCompany[] = [];
for (let i = 0; i < companies.length; i++) {
const company = companies[i];
const originId = originIds[i];
const originId = company.remote_id;

if (!originId || originId == '') {
throw new NotFoundError(`Origin id not there, found ${originId}`);
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/attio/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class AttioContactMapper implements IContactMapper {
const opts: any = {};

return {
remote_id: contact.id.record_id,
first_name: contact.values.name[0]?.first_name,
last_name: contact.values.name[0]?.last_name,
// user_id: contact.values.created_by[0]?.referenced_actor_id,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/hubspot/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class HubspotContactMapper implements IContactMapper {
};*/

return {
remote_id: contact.id,
first_name: contact.properties.firstname,
last_name: contact.properties.lastname,
email_addresses: [
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/pipedrive/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class PipedriveContactMapper implements IContactMapper {
}

return {
remote_id: contact.id,
first_name: contact.first_name,
last_name: contact.last_name,
email_addresses: contact.email.map((e) => ({
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/zendesk/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class ZendeskContactMapper implements IContactMapper {
};

return {
remote_id: String(contact.id),
first_name: contact.first_name,
last_name: contact.last_name,
email_addresses,
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/crm/contact/services/zoho/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export class ZohoContactMapper implements IContactMapper {
country: contact.Mailing_Country,
};

// TODO - Set remote_id with correct attribute
return {
remote_id: '',
first_name: contact.First_Name ? contact.First_Name : '',
last_name: contact.Last_Name ? contact.Last_Name : '',
email_addresses,
Expand Down
Loading

0 comments on commit fd18b96

Please sign in to comment.