import { Injectable, NotFoundException } from "@nestjs/common"; import { PrismaService } from "src/prisma/prisma.service"; import { CreateBankCodeDto } from "../dtos/create-bank-codes"; import { BankCodes } from "@prisma/client"; import { UpdateBankCodeDto } from "../dtos/update-bank-codes"; @Injectable() export class BankCodesService { constructor(private readonly prisma: PrismaService) {} async create(dto: CreateBankCodeDto): Promise{ return this.prisma.bankCodes.create({ data: dto }) } 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) { await this.prisma.bankCodes.update({ where: { id }, data: dto }); } async remove(id: number) { await this.findOne(id); return this.prisma.bankCodes.delete({ where: {id} }); } }