targo-backend/src/time-and-attendance/bank-codes/bank-codes.service.ts
2025-12-04 17:01:28 -05:00

47 lines
1.5 KiB
TypeScript

import { Injectable } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { PrismaService } from "src/prisma/prisma.service";
import { Result } from "src/common/errors/result-error.factory";
@Injectable()
export class BankCodesService {
constructor(private readonly prisma: PrismaService) { }
async create(dto: Prisma.BankCodesCreateInput): Promise<Result<boolean, string>> {
try {
await this.prisma.bankCodes.create({
data: {
type: dto.type,
categorie: dto.categorie,
modifier: dto.modifier,
bank_code: dto.bank_code,
},
});
} catch (error) {
return { success: false, error: 'INVALID_BANK_CODE' + error };
}
return { success: true, data: true };
}
findAll() {
return this.prisma.bankCodes.findMany();
}
async update(id: number, dto: Prisma.BankCodesUpdateInput): Promise<Result<boolean, string>> {
try {
await this.prisma.bankCodes.update({
where: { id },
data: {
type: dto.type,
categorie: dto.categorie,
modifier: dto.modifier,
bank_code: dto.bank_code,
},
});
return { success: true, data: true };
} catch (error) {
return { success: false, error: 'INVALID_BANK_CODE' + error };
}
}
}