diff --git a/packages/core/src/modules/employment/use-cases/save-company-if-necessary.ts b/packages/core/src/modules/employment/use-cases/save-company-if-necessary.ts index 3c3fdac17..142f78825 100644 --- a/packages/core/src/modules/employment/use-cases/save-company-if-necessary.ts +++ b/packages/core/src/modules/employment/use-cases/save-company-if-necessary.ts @@ -65,7 +65,11 @@ export async function saveCompanyIfNecessary( async () => { return runActor({ actorId: 'harvestapi~linkedin-company', - body: { companies: [companyNameOrLinkedInId] }, + body: { + companies: [ + `https://www.linkedin.com/company/${companyNameOrLinkedInId}`, + ], + }, }); } ); diff --git a/packages/core/src/modules/linkedin.ts b/packages/core/src/modules/linkedin.ts index a8732e002..e290bfb37 100644 --- a/packages/core/src/modules/linkedin.ts +++ b/packages/core/src/modules/linkedin.ts @@ -324,19 +324,18 @@ const LinkedInLocation = z.object({ }); const LinkedInProfile = z.object({ - element: z.object({ - education: z.array(LinkedInEducation), - experience: z.array(LinkedInExperience), - headline: z.string().nullish(), - location: LinkedInLocation, - openToWork: z.boolean().nullish(), - photo: z.string().url().nullish(), - }), + education: z.array(LinkedInEducation), + error: z.undefined(), + experience: z.array(LinkedInExperience), + headline: z.string().nullish(), + location: LinkedInLocation, + openToWork: z.boolean().nullish(), + photo: z.string().url().nullish(), originalQuery: z.object({ url: z.string() }), }); const LinkedInFailure = z.object({ - element: z.null(), + error: z.array(z.any()), originalQuery: z.object({ url: z.string() }), }); @@ -345,11 +344,11 @@ const LinkedInResult = z.union([LinkedInProfile, LinkedInFailure]); // Types type LinkedInEducation = NonNullable< - z.infer['element']['education'][number] + z.infer['education'][number] >; type LinkedInExperience = NonNullable< - z.infer['element']['experience'][number] + z.infer['experience'][number] >; type LinkedInProfile = z.infer; @@ -430,7 +429,7 @@ export async function syncLinkedInProfiles( // This is the case where there are multiple members with the same // LinkedIn URL, something that should be fixed. - if (!profile.element || !member) { + if (profile.error || !member) { await finishSync(memberId); console.log(`Profile not found for ${memberId}, moving on.`); @@ -746,7 +745,7 @@ async function scrapeProfiles(profilesToScrape: string[]) { await db.transaction().execute(async (trx) => { await Promise.all( newResults.map(async (result) => { - if (result.element) { + if (!result.error) { return successfulResults.push(result); } @@ -803,7 +802,7 @@ async function processProfile({ } }); - const checkEducationPromises = profile.element.education.map( + const checkEducationPromises = profile.education.map( async (education) => { if (!education) { return; @@ -826,7 +825,7 @@ async function processProfile({ } ); - const checkExperiencesPromises = profile.element.experience.map( + const checkExperiencesPromises = profile.experience.map( async (experience) => { if (!experience) { return; @@ -896,7 +895,7 @@ type CheckMemberInput = { async function checkMember({ member, profile, trx }: CheckMemberInput) { const updatedLocation = await run(async () => { - const locationFromLinkedIn = profile.element.location.parsed?.text; + const locationFromLinkedIn = profile.location.parsed?.text; if (!locationFromLinkedIn) { return null; @@ -914,10 +913,10 @@ async function checkMember({ member, profile, trx }: CheckMemberInput) { return getMostRelevantLocation(locationFromLinkedIn, 'geocode'); }); - if (!!profile.element.photo && !profile.element.openToWork) { + if (!!profile.photo && !profile.openToWork) { await uploadProfilePicture({ memberId: member.id, - pictureUrl: profile.element.photo, + pictureUrl: profile.photo, }); } @@ -925,7 +924,7 @@ async function checkMember({ member, profile, trx }: CheckMemberInput) { .updateTable('students') .set({ ...(!member.headline && { - headline: profile.element.headline, + headline: profile.headline, }), ...(!!updatedLocation && { currentLocation: updatedLocation.formattedAddress,