From cf25c5d0e37e773998559da7e81a5fa29d269b46 Mon Sep 17 00:00:00 2001 From: navneethkrish Date: Thu, 5 Dec 2024 20:50:18 +0530 Subject: [PATCH] fix(back office): modified team and role mapping --- apps/web-api/src/members/members.service.ts | 31 ++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/web-api/src/members/members.service.ts b/apps/web-api/src/members/members.service.ts index d514595f0..8c6852a9d 100644 --- a/apps/web-api/src/members/members.service.ts +++ b/apps/web-api/src/members/members.service.ts @@ -41,7 +41,7 @@ export class MembersService { @Inject(forwardRef(() => NotificationService)) private notificationService: NotificationService, private cacheService: CacheService - ) {} + ) { } /** * Creates a new member in the database within a transaction. @@ -426,7 +426,7 @@ export class MembersService { newTokens = await this.authService.updateEmailInAuth(newEmail, oldEmail, memberInfo.externalId) }); this.logger.info(`Email has been successfully updated from ${oldEmail} to ${newEmail}`) - await this.cacheService.reset({ service: 'members'}); + await this.cacheService.reset({ service: 'members' }); return { refreshToken: newTokens.refresh_token, idToken: newTokens.id_token, @@ -628,14 +628,16 @@ export class MembersService { const memberData: any = memberParticipantRequest.newData; const member = await this.prepareMemberFromParticipantRequest(null, memberData, null, tx); await this.mapLocationToMember(memberData, null, member, tx); - return await this.createMember(member, tx); + const createdMember = await this.createMember(member, tx); + await this.postCreateActions(); + return createdMember; } async updateMemberFromParticipantsRequest( memberUid: string, memberParticipantsRequest: ParticipantsRequest, requestorEmail: string, - isDirectoryAdmin=false + isDirectoryAdmin = false ): Promise { let result; await this.prisma.$transaction(async (tx) => { @@ -711,8 +713,8 @@ export class MembersService { 'name', 'email', 'githubHandler', 'discordHandler', 'bio', 'twitterHandler', 'linkedinHandler', 'telegramHandler', 'officeHours', 'moreDetails', 'plnStartDate', 'openToWork', - 'isVerified', 'signUpSource', 'signUpMedium', 'signUpCampaign', - 'isUserConsent', 'isSubscribedToNewsletter', 'teamOrProjectURL', + 'isVerified', 'signUpSource', 'signUpMedium', 'signUpCampaign', + 'isUserConsent', 'isSubscribedToNewsletter', 'teamOrProjectURL', ]; copyObj(memberData, member, directFields); member.email = member.email.toLowerCase().trim(); @@ -720,7 +722,7 @@ export class MembersService { : type === 'Update' ? { disconnect: true } : undefined; member['skills'] = buildMultiRelationMapping('skills', memberData, type); if (type === 'Create') { - if (Array.isArray(memberData.teamMemberRoles)) { + if (Array.isArray(memberData.teamAndRoles)) { member['teamMemberRoles'] = this.buildTeamMemberRoles(memberData); } if (Array.isArray(memberData.projectContributions)) { @@ -1125,7 +1127,7 @@ export class MembersService { * @returns result */ async verifyMembers(memberIds: string[], userEmail): Promise { - return await this.prisma.$transaction(async (tx) => { + return await this.prisma.$transaction(async (tx) => { const result = await tx.member.updateMany({ where: { uid: { in: memberIds } }, data: { @@ -1168,16 +1170,25 @@ export class MembersService { */ async updatePreference(id: string, preferences: any): Promise { const updatedMember = await this.updateMemberByUid(id, { preferences }); - await this.cacheService.reset({ service: 'members'}); + await this.cacheService.reset({ service: 'members' }); return updatedMember; } + /** + * Executes post-create actions such as resetting the cache and triggering Airtable sync. + * This ensures that the system is up-to-date with the latest changes. + */ + private async postCreateActions(): Promise { + await this.cacheService.reset({ service: 'members'}); + await this.forestadminService.triggerAirtableSync(); + } + /** * Executes post-update actions such as resetting the cache and triggering Airtable sync. * This ensures that the system is up-to-date with the latest changes. */ private async postUpdateActions(): Promise { - await this.cacheService.reset({ service: 'members'}); + await this.cacheService.reset({ service: 'members' }); await this.forestadminService.triggerAirtableSync(); }