feat(help): set-up function to build personnalized help in the help section

This commit is contained in:
Matthieu Haineault 2025-12-17 08:42:32 -05:00
parent b9c838d3e5
commit 08679b7db3
5 changed files with 88 additions and 0 deletions

View File

@ -823,6 +823,20 @@
"ModuleAccess"
]
}
},
"/help": {
"get": {
"operationId": "HomePageController_getIntroductionHelper",
"parameters": [],
"responses": {
"200": {
"description": ""
}
},
"tags": [
"HomePage"
]
}
}
},
"info": {

View File

@ -0,0 +1,16 @@
import { Controller, Get } from "@nestjs/common";
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
import { HomePageService } from "src/identity-and-account/home-page/home-page.service";
import { Modules as ModulesEnum } from ".prisma/client";
import { Access } from "src/common/decorators/module-access.decorators";
@Controller()
export class HomePageController {
constructor(private readonly homePageService: HomePageService) { }
@Get('help')
@ModuleAccessAllowed(ModulesEnum.dashboard)
async getIntroductionHelper(@Access('email') email: string) {
return await this.homePageService.buildHomePageHelpMessage(email);
}
}

View File

@ -0,0 +1,11 @@
import { Module } from "@nestjs/common";
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
import { HomePageController } from "src/identity-and-account/home-page/home-page.controller";
import { HomePageService } from "src/identity-and-account/home-page/home-page.service";
@Module({
controllers: [HomePageController],
providers: [HomePageService, EmailToIdResolver],
exports: [HomePageService],
})
export class HomePageModule { };

View File

@ -0,0 +1,41 @@
import { Injectable } from "@nestjs/common";
import { Result } from "src/common/errors/result-error.factory";
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
import { PrismaService } from "src/prisma/prisma.service";
@Injectable()
export class HomePageService {
constructor(
private readonly prisma: PrismaService,
private readonly emailresolver: EmailToIdResolver,
) { }
buildHomePageHelpMessage = async (email: string): Promise<Result<string[], string>> => {
const user_id = await this.emailresolver.resolveUserIdWithEmail(email);
if (!user_id.success) return { success: false, error: 'INVALID_EMAIL' };
const module_access = await this.prisma.userModuleAccess.findUnique({
where: { user_id: user_id.data },
select: {
dashboard: true,
employee_list: true,
employee_management: true,
personal_profile: true,
timesheets: true,
timesheets_approval: true,
},
});
if (!module_access) return { success: false, error: 'MODULE_ACCESS_NOT_FOUND' };
const help_message: string[] = [];
if (module_access.dashboard) help_message.push('dashboard');
if (module_access.personal_profile) help_message.push('personnal_profile');
if (module_access.timesheets) help_message.push('timesheets');
if (module_access.employee_list) help_message.push('employee_list');
if (module_access.employee_management) help_message.push('employee_management');
if (module_access.timesheets_approval) help_message.push('timesheets_approval');
return { success: true, data: help_message };
}
}

View File

@ -12,8 +12,11 @@ import { AccessGetService } from "src/identity-and-account/user-module-access/se
import { AccessUpdateService } from "src/identity-and-account/user-module-access/services/module-access-update.service";
import { UsersService } from "src/identity-and-account/users-management/services/users.service";
import { UsersModule } from "src/identity-and-account/users-management/users.module";
import { HomePageModule } from "src/identity-and-account/home-page/home-page.module";
import { EmployeesCreateService } from "src/identity-and-account/employees/services/employees-create.service";
import { EmployeesUpdateService } from "src/identity-and-account/employees/services/employees-update.service";
import { HomePageController } from "src/identity-and-account/home-page/home-page.controller";
import { HomePageService } from "src/identity-and-account/home-page/home-page.service";
@Module({
imports: [
@ -21,11 +24,13 @@ import { EmployeesUpdateService } from "src/identity-and-account/employees/servi
EmployeesModule,
PreferencesModule,
ModuleAccessModule,
HomePageModule,
],
controllers: [
EmployeesController,
PreferencesController,
ModuleAccessController,
HomePageController,
],
providers: [
EmployeesGetService,
@ -36,6 +41,7 @@ import { EmployeesUpdateService } from "src/identity-and-account/employees/servi
EmailToIdResolver,
AccessUpdateService,
AccessGetService,
HomePageService,
],
})
export class IdentityAndAccountModule { };