diff --git a/src/identity-and-account/authentication/controllers/auth.controller.ts b/src/identity-and-account/authentication/controllers/auth.controller.ts index fa38c47..dc526e9 100644 --- a/src/identity-and-account/authentication/controllers/auth.controller.ts +++ b/src/identity-and-account/authentication/controllers/auth.controller.ts @@ -17,8 +17,8 @@ export class AuthController { @Get('/callback') @UseGuards(OIDCLoginGuard) loginCallback(@Req() req: Request, @Res() res: Response) { - // res.redirect('http://10.100.251.2:9011/#/login-success'); - res.redirect('http://localhost:9000/#/login-success'); + res.redirect("http://10.100.251.2:9013/#/v1/login-success"); + // res.redirect(process.env.REDIRECT_URL_DEV!); } @Get('/me') diff --git a/src/identity-and-account/employees/employees.controller.ts b/src/identity-and-account/employees/employees.controller.ts index e3eed2e..7b68d6d 100644 --- a/src/identity-and-account/employees/employees.controller.ts +++ b/src/identity-and-account/employees/employees.controller.ts @@ -23,7 +23,7 @@ export class EmployeesController { } @Get('profile') - @ModuleAccessAllowed(ModulesEnum.employee_management) + @ModuleAccessAllowed(ModulesEnum.personal_profile) async findProfile(@Access('email') email: string, @Query('employee_email') employee_email?: string, ): Promise, string>> { return await this.getService.findOneDetailedProfile(email, employee_email); diff --git a/src/identity-and-account/home-page/home-page.controller.ts b/src/identity-and-account/help/home-page.controller.ts similarity index 87% rename from src/identity-and-account/home-page/home-page.controller.ts rename to src/identity-and-account/help/home-page.controller.ts index 870f501..50bbe5f 100644 --- a/src/identity-and-account/home-page/home-page.controller.ts +++ b/src/identity-and-account/help/home-page.controller.ts @@ -1,6 +1,6 @@ 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 { HomePageService } from "src/identity-and-account/help/home-page.service"; import { Modules as ModulesEnum } from ".prisma/client"; import { Access } from "src/common/decorators/module-access.decorators"; diff --git a/src/identity-and-account/home-page/home-page.module.ts b/src/identity-and-account/help/home-page.module.ts similarity index 60% rename from src/identity-and-account/home-page/home-page.module.ts rename to src/identity-and-account/help/home-page.module.ts index 77c6ec8..03b0e98 100644 --- a/src/identity-and-account/home-page/home-page.module.ts +++ b/src/identity-and-account/help/home-page.module.ts @@ -1,7 +1,7 @@ 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"; +import { HomePageController } from "src/identity-and-account/help/home-page.controller"; +import { HomePageService } from "src/identity-and-account/help/home-page.service"; @Module({ controllers: [HomePageController], diff --git a/src/identity-and-account/home-page/home-page.service.ts b/src/identity-and-account/help/home-page.service.ts similarity index 98% rename from src/identity-and-account/home-page/home-page.service.ts rename to src/identity-and-account/help/home-page.service.ts index bd49cfb..acaa516 100644 --- a/src/identity-and-account/home-page/home-page.service.ts +++ b/src/identity-and-account/help/home-page.service.ts @@ -30,7 +30,7 @@ export class HomePageService { 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.personal_profile) help_message.push('personal_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'); diff --git a/src/identity-and-account/identity-and-account.module.ts b/src/identity-and-account/identity-and-account.module.ts index 90c6601..8031a91 100644 --- a/src/identity-and-account/identity-and-account.module.ts +++ b/src/identity-and-account/identity-and-account.module.ts @@ -12,11 +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 { HomePageModule } from "src/identity-and-account/help/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"; +import { HomePageController } from "src/identity-and-account/help/home-page.controller"; +import { HomePageService } from "src/identity-and-account/help/home-page.service"; @Module({ imports: [ diff --git a/src/main.ts b/src/main.ts index d4b520d..c847ba5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,14 +4,12 @@ if (!(globalThis as any).crypto) { (globalThis as any).crypto = nodeCrypto; } import { ensureAttachmentsTmpDir } from './time-and-attendance/attachments/config/attachment.fs'; -import { resolveAttachmentsRoot } from './time-and-attendance/attachments/config/attachment.config';// log to be removed post dev -import { ATT_TMP_DIR } from './time-and-attendance/attachments/config/attachment.config'; // log to be removed post dev import { NestFactory, Reflector } from '@nestjs/core'; import { AppModule } from './app.module'; // import { JwtAuthGuard } from './modules/authentication/guards/jwt-auth.guard'; import { ModulesGuard } from './common/guards/modules.guard'; -import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; -import { writeFileSync } from 'fs'; +// import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; +// import { writeFileSync } from 'fs'; import * as session from 'express-session'; import * as passport from 'passport'; import { PrismaService } from 'src/prisma/prisma.service'; @@ -59,40 +57,35 @@ async function bootstrap() { credentials: true, }); - //swagger config - const config = new DocumentBuilder() - .setTitle('Targo_Backend') - .setDescription('Documentation de l`API REST pour Targo (NestJS + Prisma)') - .setVersion('1.0') - .addBearerAuth({ - type: 'http', - scheme: 'bearer', - bearerFormat: 'JWT', - name: 'Authorization', - description: 'Invalid JWT token', - in: 'header', - }, 'access-token') - .addTag('Users') - .addTag('Employees') - .addTag('Customers') - .addTag('Timesheets') - .addTag('Shifts') - .addTag('Leave Requests') - .addTag('Shift Codes') - .addTag('OAuth Access Tokens') - .addTag('Authorization') - .build(); + // //swagger config + // const config = new DocumentBuilder() + // .setTitle('Targo_Backend') + // .setDescription('Documentation de l`API REST pour Targo (NestJS + Prisma)') + // .setVersion('1.0') + // .addBearerAuth({ + // type: 'http', + // scheme: 'bearer', + // bearerFormat: 'JWT', + // name: 'Authorization', + // description: 'Invalid JWT token', + // in: 'header', + // }, 'access-token') + // .addTag('Users') + // .addTag('Employees') + // .addTag('Customers') + // .addTag('Timesheets') + // .addTag('Shifts') + // .addTag('Leave Requests') + // .addTag('Shift Codes') + // .addTag('OAuth Access Tokens') + // .addTag('Authorization') + // .build(); - //document builder for swagger docs - const documentFactory = () => SwaggerModule.createDocument(app, config); - const document = documentFactory() - SwaggerModule.setup('api/docs', app, document); - writeFileSync('./docs/swagger/swagger-spec.json', JSON.stringify(document, null, 2)); - - // logs to be removed post dev - console.log('[ENV.ATTACHMENTS_ROOT]', process.env.ATTACHMENTS_ROOT); - console.log('[resolveAttachmentsRoot()]', resolveAttachmentsRoot()); - console.log('[ATT_TMP_DIR()]', ATT_TMP_DIR()); + // //document builder for swagger docs + // const documentFactory = () => SwaggerModule.createDocument(app, config); + // const document = documentFactory() + // SwaggerModule.setup('api/docs', app, document); + // writeFileSync('./docs/swagger/swagger-spec.json', JSON.stringify(document, null, 2)); await ensureAttachmentsTmpDir(); await app.listen(process.env.PORT ?? 3000); diff --git a/src/time-and-attendance/bank-codes/bank-codes.controller.ts b/src/time-and-attendance/bank-codes/bank-codes.controller.ts index 23048a8..550847c 100644 --- a/src/time-and-attendance/bank-codes/bank-codes.controller.ts +++ b/src/time-and-attendance/bank-codes/bank-codes.controller.ts @@ -13,20 +13,17 @@ export class BankCodesControllers { //_____________________________________________________________________________________________ @Post() - @ModuleAccessAllowed(ModulesEnum.employee_management) create(@Body() dto: Prisma.BankCodesCreateInput ): Promise> { return this.bankCodesService.create(dto); } @Get() - @ModuleAccessAllowed(ModulesEnum.employee_management) findAll() { return this.bankCodesService.findAll(); } @Patch(':id') - @ModuleAccessAllowed(ModulesEnum.employee_management) update(@Param('id', ParseIntPipe) id: number, @Body() dto: Prisma.BankCodesUpdateInput ): Promise> { return this.bankCodesService.update(id, dto) diff --git a/src/time-and-attendance/pay-period/pay-periods.controller.ts b/src/time-and-attendance/pay-period/pay-periods.controller.ts index e900cae..52ba773 100644 --- a/src/time-and-attendance/pay-period/pay-periods.controller.ts +++ b/src/time-and-attendance/pay-period/pay-periods.controller.ts @@ -17,7 +17,7 @@ export class PayPeriodsController { ) { } @Get('current-and-all') - @ModuleAccessAllowed(ModulesEnum.timesheets_approval) + @ModuleAccessAllowed(ModulesEnum.timesheets) async getCurrentAndAll(@Query('date') date?: string): Promise> { const current = await this.queryService.findCurrent(date); if (!current.success) return { success: false, error: 'INVALID_PAY_PERIOD' }; @@ -29,13 +29,13 @@ export class PayPeriodsController { } @Get("date/:date") - @ModuleAccessAllowed(ModulesEnum.timesheets_approval) + @ModuleAccessAllowed(ModulesEnum.timesheets) async findByDate(@Param("date") date: string) { return this.queryService.findByDate(date); } @Get(":year/:periodNumber") - @ModuleAccessAllowed(ModulesEnum.timesheets_approval) + @ModuleAccessAllowed(ModulesEnum.timesheets) async findOneByYear( @Param("year", ParseIntPipe) year: number, @Param("periodNumber", ParseIntPipe) period_no: number, diff --git a/src/time-and-attendance/schedule-presets/schedule-presets.controller.ts b/src/time-and-attendance/schedule-presets/schedule-presets.controller.ts index 7293438..7da9c20 100644 --- a/src/time-and-attendance/schedule-presets/schedule-presets.controller.ts +++ b/src/time-and-attendance/schedule-presets/schedule-presets.controller.ts @@ -43,7 +43,7 @@ export class SchedulePresetsController { @Delete('delete/:id') @ModuleAccessAllowed(ModulesEnum.employee_management) async deletePreset( - @Param('id', ParseIntPipe) id: number) { + @Param('id') id: number) { return await this.deleteService.deletePreset(id); } diff --git a/src/time-and-attendance/schedule-presets/schedule-presets.dto.ts b/src/time-and-attendance/schedule-presets/schedule-presets.dto.ts index 13edcbc..0f36838 100644 --- a/src/time-and-attendance/schedule-presets/schedule-presets.dto.ts +++ b/src/time-and-attendance/schedule-presets/schedule-presets.dto.ts @@ -5,7 +5,6 @@ import { HH_MM_REGEX } from "src/common/utils/constants.utils"; export class SchedulePresetsDto { @IsInt() id!: number; @IsString() name!: string; - @IsBoolean() @IsOptional() is_default: boolean; @IsArray() @ArrayMinSize(1) shifts: SchedulePresetShiftsDto[]; } diff --git a/src/time-and-attendance/schedule-presets/services/schedule-presets-apply.service.ts b/src/time-and-attendance/schedule-presets/services/schedule-presets-apply.service.ts index 27bb1fe..668418a 100644 --- a/src/time-and-attendance/schedule-presets/services/schedule-presets-apply.service.ts +++ b/src/time-and-attendance/schedule-presets/services/schedule-presets-apply.service.ts @@ -32,7 +32,6 @@ export class SchedulePresetsApplyService { schedule_preset: { select: { id: true, - is_default: true, shifts: true, }, }, @@ -94,7 +93,6 @@ export class SchedulePresetsApplyService { schedule_preset: { select: { id: true, - is_default: true, shifts: { where: { week_day: $Enums.Weekday[week_day] }, select: { diff --git a/src/time-and-attendance/schedule-presets/services/schedule-presets-create.service.ts b/src/time-and-attendance/schedule-presets/services/schedule-presets-create.service.ts index f152856..06be417 100644 --- a/src/time-and-attendance/schedule-presets/services/schedule-presets-create.service.ts +++ b/src/time-and-attendance/schedule-presets/services/schedule-presets-create.service.ts @@ -56,17 +56,17 @@ export class SchedulePresetsCreateService { await this.prisma.$transaction(async (tx) => { //check if employee chose this preset has a default preset and ensure all others are false - if (dto.is_default) { - await tx.schedulePresets.updateMany({ - where: { is_default: true }, - data: { is_default: false }, - }); - } + // if (dto.is_default) { + // await tx.schedulePresets.updateMany({ + // where: { is_default: true }, + // data: { is_default: false }, + // }); + // } await tx.schedulePresets.create({ data: { name: dto.name, - is_default: dto.is_default ?? false, + // is_default: dto.is_default ?? false, shifts: { create: dto.shifts.map((shift, index) => { //validated bank_codes sent as a Result Array to access its data diff --git a/src/time-and-attendance/schedule-presets/services/schedule-presets-delete.service.ts b/src/time-and-attendance/schedule-presets/services/schedule-presets-delete.service.ts index 4496dcd..62730c1 100644 --- a/src/time-and-attendance/schedule-presets/services/schedule-presets-delete.service.ts +++ b/src/time-and-attendance/schedule-presets/services/schedule-presets-delete.service.ts @@ -1,6 +1,8 @@ +import { Injectable } from "@nestjs/common"; import { Result } from "src/common/errors/result-error.factory"; import { PrismaService } from "src/prisma/prisma.service"; +@Injectable() export class SchedulePresetDeleteService { constructor(private readonly prisma: PrismaService) { } @@ -8,19 +10,22 @@ export class SchedulePresetDeleteService { // DELETE //_________________________________________________________________ async deletePreset(preset_id: number): Promise> { - const preset = await this.prisma.schedulePresets.findFirst({ + console.log('preset_id received: ', preset_id) + + const preset = await this.prisma.schedulePresets.findUnique({ where: { id: preset_id }, select: { id: true }, }); if (!preset) return { success: false, error: `SCHEDULE_PRESET_NOT_FOUND` }; - - await this.prisma.employees.updateMany({ - where: { schedule_preset_id: preset.id }, + console.log('preset found: ', preset.id) + + const updated_employees = await this.prisma.employees.updateMany({ + where: { schedule_preset_id: preset_id }, data: { - schedule_preset_id: null, + schedule_preset_id: 0, }, - }); + console.log('employee schedule id updated', updated_employees); await this.prisma.$transaction(async (tx) => { await tx.schedulePresetShifts.deleteMany({ where: { preset_id: preset_id } }); diff --git a/src/time-and-attendance/schedule-presets/services/schedule-presets-get.service.ts b/src/time-and-attendance/schedule-presets/services/schedule-presets-get.service.ts index ed641a4..af8efe9 100644 --- a/src/time-and-attendance/schedule-presets/services/schedule-presets-get.service.ts +++ b/src/time-and-attendance/schedule-presets/services/schedule-presets-get.service.ts @@ -15,7 +15,7 @@ export class SchedulePresetsGetService { async getSchedulePresets(): Promise> { try { const presets = await this.prisma.schedulePresets.findMany({ - orderBy: [{ is_default: 'desc' }, { name: 'asc' }], + orderBy: [{ name: 'asc' }], include: { shifts: { orderBy: [{ week_day: 'asc' }, { start_time: 'asc' }], @@ -28,7 +28,6 @@ export class SchedulePresetsGetService { const response: SchedulePresetsDto[] = presets.map((preset) => ({ id: preset.id, name: preset.name, - is_default: preset.is_default, shifts: preset.shifts.map>((shift) => ({ preset_id: shift.preset_id, week_day: shift.week_day, diff --git a/src/time-and-attendance/schedule-presets/services/schedule-presets-update.service.ts b/src/time-and-attendance/schedule-presets/services/schedule-presets-update.service.ts index 3b6a9b7..57998c5 100644 --- a/src/time-and-attendance/schedule-presets/services/schedule-presets-update.service.ts +++ b/src/time-and-attendance/schedule-presets/services/schedule-presets-update.service.ts @@ -22,7 +22,6 @@ export class SchedulePresetUpdateService { where: { id: dto.id }, select: { id: true, - is_default: true, shifts: true, }, }); @@ -52,22 +51,12 @@ export class SchedulePresetUpdateService { } await this.prisma.$transaction(async (tx) => { - if (dto.is_default) { - await tx.schedulePresets.updateMany({ - where: { - is_default: true, - NOT: { id: existing.id }, - }, - data: { is_default: false }, - }); - } await tx.schedulePresetShifts.deleteMany({ where: { preset_id: existing.id } }); await tx.schedulePresets.update({ where: { id: existing.id }, data: { name: dto.name, - is_default: dto.is_default ?? false, shifts: { create: dto.shifts.map((shift, index) => { const result = bank_code_results[index] as { success: true, data: number }; diff --git a/src/time-and-attendance/timesheets/timesheet.controller.ts b/src/time-and-attendance/timesheets/timesheet.controller.ts index eb5050a..448f459 100644 --- a/src/time-and-attendance/timesheets/timesheet.controller.ts +++ b/src/time-and-attendance/timesheets/timesheet.controller.ts @@ -14,7 +14,7 @@ export class TimesheetController { ) { } @Get(':year/:period_number') - @ModuleAccessAllowed(ModulesEnum.timesheets_approval) + @ModuleAccessAllowed(ModulesEnum.timesheets) getTimesheetByPayPeriod( @Access('email') email: string, @Param('year', ParseIntPipe) year: number,