65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { Prisma } from "prisma/postgres/generated/prisma/client/postgres/client";
|
|
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
|
import { Result } from "src/common/errors/result-error.factory";
|
|
|
|
@Injectable()
|
|
export class BankCodesService {
|
|
constructor(private readonly prisma: PrismaPostgresService) { }
|
|
|
|
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,
|
|
},
|
|
});
|
|
return { success: true, data: true };
|
|
} catch (error) {
|
|
return { success: false, error: 'INVALID_BANK_CODE' + error };
|
|
}
|
|
}
|
|
|
|
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 };
|
|
}
|
|
}
|
|
|
|
async delete(
|
|
id: number
|
|
): Promise<Result<boolean, string>> {
|
|
try {
|
|
await this.prisma.bankCodes.delete({
|
|
where: { id },
|
|
});
|
|
return { success: true, data: true };
|
|
} catch (error) {
|
|
return { success: false, error: 'INVALID_BANK_CODE_ID' + error };
|
|
}
|
|
}
|
|
|
|
} |