import { Injectable } from "@nestjs/common"; import { Result } from "src/common/errors/result-error.factory"; import { PrismaService } from "prisma/postgres/prisma-postgres.service"; @Injectable() export class MileageService { constructor(private readonly prisma: PrismaService) { } public async calculateReimbursement(amount: number, bank_code_id: number): Promise> { if (amount < 0) return { success: false, error: 'The amount must be higher than 0' }; //fetch modifier const bank_code = await this.prisma.bankCodes.findUnique({ where: { id: bank_code_id }, select: { modifier: true, type: true }, }); if (!bank_code) return { success: false, error: `bank_code ${bank_code_id} not found` } //calculate total amount to reimburs const reimboursement = amount * bank_code.modifier; const result = parseFloat(reimboursement.toFixed(2)); return { success: true, data: result }; } }