20251224
This commit is contained in:
parent
1259ba76c9
commit
6454e1b46b
19 changed files with 667 additions and 611 deletions
|
|
@ -8,7 +8,7 @@ const hubspotClient = new Client({ accessToken: process.env.HUBSPOT_ACCESS_TOKEN
|
|||
export const CompanySchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
})
|
||||
});
|
||||
|
||||
export const OwnerSchema = z.object({
|
||||
id: z.string(),
|
||||
|
|
@ -19,9 +19,16 @@ export type Company = z.infer<typeof CompanySchema>;
|
|||
export type Owner = z.infer<typeof OwnerSchema>;
|
||||
|
||||
export const hubspotController = {
|
||||
check: async() => {
|
||||
const response = await hubspotClient.crm.companies.getAll();
|
||||
console.log(response.length);
|
||||
check: async(): Promise<boolean | null> => {
|
||||
try {
|
||||
const response = await hubspotClient.crm.companies.getAll();
|
||||
console.log(response.length);
|
||||
console.log("HubSpot connection check successful.");
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("HubSpot connection check failed:", error);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
getCompanies: async(): Promise<Company[] | null> => {
|
||||
try {
|
||||
|
|
@ -33,9 +40,9 @@ export const hubspotController = {
|
|||
const response = await hubspotClient.crm.companies.basicApi.getPage(limit, after);
|
||||
// console.log(response.results);
|
||||
const companies: Company[] = response.results.map((company) => CompanySchema.parse({
|
||||
id: company.id,
|
||||
name: company.properties.name,
|
||||
}));
|
||||
id: company.id,
|
||||
name: company.properties.name ?? '',
|
||||
}));
|
||||
allCompanies.push(...companies);
|
||||
|
||||
if(response.paging && response.paging.next && response.paging.next.after) {
|
||||
|
|
@ -46,6 +53,7 @@ export const hubspotController = {
|
|||
}
|
||||
return allCompanies;
|
||||
} catch (error) {
|
||||
console.error("Error fetching companies:", error);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue