From f499abbb7825f8b7069ec3c154076d0ca30a7a62 Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Fri, 28 Nov 2025 10:01:59 -0500 Subject: [PATCH] fix(userModuleAccess): small return fixes --- .../services/preferences.service.ts | 1 - .../dtos/module-acces.dto.ts | 2 +- .../services/module-access-get.service.ts | 2 +- .../services/module-access-update.service.ts | 32 ++++++++++++++----- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/identity-and-account/preferences/services/preferences.service.ts b/src/identity-and-account/preferences/services/preferences.service.ts index b03db61..a41151d 100644 --- a/src/identity-and-account/preferences/services/preferences.service.ts +++ b/src/identity-and-account/preferences/services/preferences.service.ts @@ -1,6 +1,5 @@ import { DisplayLanguage, PreferencesDto } from "../dtos/preferences.dto"; import { PrismaService } from "src/prisma/prisma.service"; -import { Preferences } from "@prisma/client"; import { Injectable } from "@nestjs/common"; import { Result } from "src/common/errors/result-error.factory"; import { EmailToIdResolver } from "src/common/mappers/email-id.mapper"; diff --git a/src/identity-and-account/user-module-access/dtos/module-acces.dto.ts b/src/identity-and-account/user-module-access/dtos/module-acces.dto.ts index 5de04d9..5e1e6be 100644 --- a/src/identity-and-account/user-module-access/dtos/module-acces.dto.ts +++ b/src/identity-and-account/user-module-access/dtos/module-acces.dto.ts @@ -5,6 +5,6 @@ export class ModuleAccess { @IsBoolean() timesheets_approval!: boolean; @IsBoolean() employee_list!: boolean; @IsBoolean() employee_management!: boolean; - @IsBoolean() personnal_profile!: boolean; + @IsBoolean() personal_profile!: boolean; @IsBoolean() dashboard!: boolean; } \ No newline at end of file diff --git a/src/identity-and-account/user-module-access/services/module-access-get.service.ts b/src/identity-and-account/user-module-access/services/module-access-get.service.ts index 5aaf07d..86a7bfd 100644 --- a/src/identity-and-account/user-module-access/services/module-access-get.service.ts +++ b/src/identity-and-account/user-module-access/services/module-access-get.service.ts @@ -34,7 +34,7 @@ export class AccessGetService { timesheets_approval: access.timesheets_approval, employee_list: access.employee_list, employee_management: access.employee_management, - personnal_profile: access.personal_profile, + personal_profile: access.personal_profile, dashboard: access.dashboard, }; return { success: true, data: granted_access } diff --git a/src/identity-and-account/user-module-access/services/module-access-update.service.ts b/src/identity-and-account/user-module-access/services/module-access-update.service.ts index 051a1a5..8fbb1c8 100644 --- a/src/identity-and-account/user-module-access/services/module-access-update.service.ts +++ b/src/identity-and-account/user-module-access/services/module-access-update.service.ts @@ -11,7 +11,7 @@ export class AccessUpdateService { private readonly emailResolver: EmailToIdResolver, ) { } - async updateModuleAccess(email: string, dto: ModuleAccess, employee_email?: string): Promise> { + async updateModuleAccess(email: string, dto: ModuleAccess, employee_email?: string): Promise> { const account_email = employee_email ?? email; const user_id = await this.emailResolver.resolveUserIdWithEmail(account_email); if (!user_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }; @@ -30,21 +30,29 @@ export class AccessUpdateService { }); if (!orignal_access) return { success: false, error: 'MODULE_ACCESS_NOT_FOUND' }; - await this.prisma.userModuleAccess.update({ + const updated_access:ModuleAccess = await this.prisma.userModuleAccess.update({ where: { id: orignal_access.id }, data: { timesheets: dto.timesheets, timesheets_approval: dto.timesheets_approval, employee_list: dto.employee_list, employee_management: dto.employee_management, - personal_profile: dto.personnal_profile, + personal_profile: dto.personal_profile, dashboard: dto.dashboard, + }, + select: { + timesheets: true, + timesheets_approval: true, + employee_list: true, + employee_management: true, + personal_profile: true, + dashboard: true, } }) - return { success: true, data: true }; + return { success: true, data: updated_access }; } - async revokeModuleAccess(email: string, employee_email?: string): Promise> { + async revokeModuleAccess(email: string, employee_email?: string): Promise> { const account_email = employee_email ?? email; const user_id = await this.emailResolver.resolveUserIdWithEmail(account_email); if (!user_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }; @@ -55,7 +63,7 @@ export class AccessUpdateService { }); if (!access) return { success: false, error: 'MODULE_ACCESS_NOT_FOUND' }; - await this.prisma.userModuleAccess.update({ + const revoked_access: ModuleAccess = await this.prisma.userModuleAccess.update({ where: { id: access.id }, data: { timesheets: false, @@ -63,10 +71,18 @@ export class AccessUpdateService { employee_list: false, employee_management: false, personal_profile: false, - dashboard: true, + dashboard: false, }, + select: { + timesheets: true, + timesheets_approval: true, + employee_list: true, + employee_management: true, + personal_profile: true, + dashboard: true, + } }); - return { success: true, data: true }; + return { success: true, data: revoked_access }; } } \ No newline at end of file