targo-backend/src/modules/bank-codes/services/bank-codes.service.ts

51 lines
1.5 KiB
TypeScript

import { Injectable, NotFoundException } from "@nestjs/common";
import { PrismaService } from "src/prisma/prisma.service";
import { CreateBankCodeDto } from "../dtos/create-bank-code.dto";
import { BankCodes } from "@prisma/client";
import { UpdateBankCodeDto } from "../dtos/update-bank-code.dto";
@Injectable()
export class BankCodesService {
constructor(private readonly prisma: PrismaService) {}
async create(dto: CreateBankCodeDto): Promise<BankCodes>{
return this.prisma.bankCodes.create({
data: {
type: dto.type,
categorie: dto.categorie,
modifier: dto.modifier,
bank_code: dto.bank_code,
},
});
}
findAll() {
return this.prisma.bankCodes.findMany();
}
async findOne(id: number) {
const bankCode = await this.prisma.bankCodes.findUnique({ where: {id} });
if(!bankCode) throw new NotFoundException(`Bank Code #${id} not found`);
return bankCode;
}
async update(id:number, dto: UpdateBankCodeDto) {
return await this.prisma.bankCodes.update({
where: { id },
data: {
type: dto.type,
categorie: dto.categorie,
modifier: dto.modifier as any,
bank_code: dto.bank_code,
},
});
}
async remove(id: number) {
await this.findOne(id);
return this.prisma.bankCodes.delete({ where: {id} });
}
}