Skip to content

Commit

Permalink
fix(back office): modified team and role mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
navneethkrish authored and madan-ideas2it committed Dec 5, 2024
1 parent a079128 commit cf25c5d
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions apps/web-api/src/members/members.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<Member> {
let result;
await this.prisma.$transaction(async (tx) => {
Expand Down Expand Up @@ -711,16 +713,16 @@ 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();
member['image'] = memberData.imageUid ? { connect: { uid: memberData.imageUid } }
: 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)) {
Expand Down Expand Up @@ -1125,7 +1127,7 @@ export class MembersService {
* @returns result
*/
async verifyMembers(memberIds: string[], userEmail): Promise<any> {
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: {
Expand Down Expand Up @@ -1168,16 +1170,25 @@ export class MembersService {
*/
async updatePreference(id: string, preferences: any): Promise<Member> {
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<void> {
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<void> {
await this.cacheService.reset({ service: 'members'});
await this.cacheService.reset({ service: 'members' });
await this.forestadminService.triggerAirtableSync();
}

Expand Down

0 comments on commit cf25c5d

Please sign in to comment.