Skip to content

Commit

Permalink
fix(linkedin): incldue social id with fetched profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
adelinaenache committed Jun 17, 2024
1 parent 22d5a38 commit d3841f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/connections/connections.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,26 @@ export class ConnectionsService {
// If the account exists, we just return the user associated with it.
const profileUrl = Buffer.from(profileUrlBase64, 'base64').toString();

// Fetch the profile details
const profileData = await new ProfileFetcherDelegator(
profileUrl,
).getProfileDetails();

const socialAccount = await this.prisma.socialAccount.findFirst({
where: { profileUrl },
where: {
OR: [
{ profileUrl },
{
socialId: profileData.socialId,
},
],
},
include: {
user: { include: this.includeWithUserConnection() },
},
});
if (socialAccount) return this.convertConnectionToDto(socialAccount.user);

// Fetch the profile details
const profileData = await new ProfileFetcherDelegator(
profileUrl,
).getProfileDetails();

// Else, we create a new user, associate the social account with it, and return the user.

const newUserId = v4();
Expand All @@ -188,6 +195,7 @@ export class ConnectionsService {
data: {
platform: profileData.socialAccountType,
profileUrl,
socialId: profileData.socialId,
userId: newUserId,
},
}),
Expand Down
1 change: 1 addition & 0 deletions src/user/profile-fetcher/base.profile-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface ProfileDetails {
name?: string;
headline?: string;
profilePictureUrl?: string;
socialId?: string;
}
1 change: 1 addition & 0 deletions src/user/profile-fetcher/linkedin.profile-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class LinkedInProfileFetcher extends ProfileFetcher {
socialAccountType: SocialAccountType.LINKEDIN,
profileUrl: this.profileUrl,
headline: data.data.job_title,
socialId: data.data.profile_id,
profilePictureUrl: data.data.profile_image_url,
};
} else {
Expand Down

0 comments on commit d3841f3

Please sign in to comment.