cleaning(): more cleaning and imports ajustements

This commit is contained in:
Matthieu Haineault 2025-11-14 09:39:15 -05:00
parent 1589df979f
commit 8c816da286
5 changed files with 19 additions and 13 deletions

View File

@ -23,25 +23,27 @@ export class BankCodesResolver {
}; };
//finds only id by type //finds only id by type
readonly findBankCodeIDByType = async (type: string, client?: Tx): Promise<Result<number, string>> => { readonly findBankCodeIDByType = async (type: string, client?: Tx
): Promise<Result<number, string>> => {
const db = client ?? this.prisma; const db = client ?? this.prisma;
const bank_code = await db.bankCodes.findFirst({ const bank_code = await db.bankCodes.findFirst({
where: { type }, where: { type },
select: { id: true }, select: { id: true },
}); });
if (!bank_code) return { success: false, error:`Unkown bank type: ${type}`}; if (!bank_code) return { success: false, error: `Unkown bank type: ${type}` };
return { success: true, data: bank_code.id}; return { success: true, data: bank_code.id };
} }
readonly findTypeByBankCodeId = async (bank_code_id: number, client?: Tx): Promise<Result<string, string>> => { readonly findTypeByBankCodeId = async (bank_code_id: number, client?: Tx
): Promise<Result<string, string>> => {
const db = client ?? this.prisma; const db = client ?? this.prisma;
const bank_code = await db.bankCodes.findFirst({ const bank_code = await db.bankCodes.findFirst({
where: { id: bank_code_id }, where: { id: bank_code_id },
select: { type: true }, select: { type: true },
}); });
if (!bank_code) return {success: false, error: `Type with id : ${bank_code_id} not found` } if (!bank_code) return { success: false, error: `Type with id : ${bank_code_id} not found` }
return {success: true, data: bank_code.type}; return { success: true, data: bank_code.type };
} }
} }

View File

@ -11,7 +11,8 @@ export class EmailToIdResolver {
constructor(private readonly prisma: PrismaService) { } constructor(private readonly prisma: PrismaService) { }
// find employee_id using email // find employee_id using email
readonly findIdByEmail = async (email: string, client?: Tx): Promise<Result<number, string>> => { readonly findIdByEmail = async (email: string, client?: Tx
): Promise<Result<number, string>> => {
const db = client ?? this.prisma; const db = client ?? this.prisma;
const employee = await db.employees.findFirst({ const employee = await db.employees.findFirst({
where: { user: { email } }, where: { user: { email } },

View File

@ -15,12 +15,13 @@ interface ShiftKey {
} }
export class ShiftIdResolver { export class ShiftIdResolver {
constructor(private readonly prisma: PrismaService) {} constructor(private readonly prisma: PrismaService) { }
readonly findShiftIdByData = async ( key: ShiftKey, client?: Tx ): Promise<Result<number, string>> => { readonly findShiftIdByData = async (key: ShiftKey, client?: Tx
): Promise<Result<number, string>> => {
const db = client ?? this.prisma; const db = client ?? this.prisma;
const shift = await db.shifts.findFirst({ const shift = await db.shifts.findFirst({
where: { where: {
timesheet_id: key.timesheet_id, timesheet_id: key.timesheet_id,
bank_code_id: key.bank_code_id, bank_code_id: key.bank_code_id,
date: key.date, date: key.date,
@ -31,9 +32,8 @@ export class ShiftIdResolver {
}, },
select: { id: true }, select: { id: true },
}); });
if (!shift) return { success: false, error: `shift not found` }
if(!shift) return { success: false, error: `shift not found`}
return { success: true, data: shift.id }; return { success: true, data: shift.id };
}; };
} }

View File

@ -1,4 +1,5 @@
import { Module } from "@nestjs/common"; import { Module } from "@nestjs/common";
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
import { EmployeesController } from "src/identity-and-account/employees/controllers/employees.controller"; import { EmployeesController } from "src/identity-and-account/employees/controllers/employees.controller";
import { EmployeesModule } from "src/identity-and-account/employees/employees.module"; import { EmployeesModule } from "src/identity-and-account/employees/employees.module";
import { EmployeesArchivalService } from "src/identity-and-account/employees/services/employees-archival.service"; import { EmployeesArchivalService } from "src/identity-and-account/employees/services/employees-archival.service";
@ -24,6 +25,7 @@ import { UsersModule } from "src/identity-and-account/users-management/users.mod
EmployeesService, EmployeesService,
PreferencesService, PreferencesService,
UsersService, UsersService,
EmailToIdResolver,
], ],
}) })
export class IdentityAndAccountModule { }; export class IdentityAndAccountModule { };

View File

@ -1,10 +1,11 @@
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
import { PreferencesController } from "./controllers/preferences.controller"; import { PreferencesController } from "./controllers/preferences.controller";
import { PreferencesService } from "./services/preferences.service"; import { PreferencesService } from "./services/preferences.service";
import { Module } from "@nestjs/common"; import { Module } from "@nestjs/common";
@Module({ @Module({
controllers: [ PreferencesController ], controllers: [ PreferencesController ],
providers: [ PreferencesService ], providers: [ PreferencesService, EmailToIdResolver ],
exports: [ PreferencesService ], exports: [ PreferencesService ],
}) })