From 7f9112c866132fef6ac951fbb1cb51427e50eaf9 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Thu, 3 Oct 2024 13:59:46 +0700 Subject: [PATCH] refactor: make field optional --- src/controllers/05-quotation-controller.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index 90d8e60..85da40b 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -15,8 +15,6 @@ import { } from "tsoa"; import { RequestWithUser } from "../interfaces/user"; import prisma from "../db"; -import HttpError from "../interfaces/http-error"; -import HttpStatus from "../interfaces/http-status"; import { branchRelationPermInclude, createPermCheck, @@ -73,7 +71,7 @@ type QuotationCreate = { * @maximum 1 * @minimum 0 */ - discount: number; + discount?: number; pricePerUnit?: number; /** * @maximum 1 @@ -332,14 +330,14 @@ export class QuotationController extends Controller { serviceId: v.serviceId, pricePerUnit: v.pricePerUnit || product.find((p) => p.id === v.productId)?.price || 0, amount: v.amount, - discount: v.discount, + discount: v.discount || 0, vat: v.vat || VAT_DEFAULT, })); const price = list.reduce( (a, c) => { const price = c.pricePerUnit * c.amount; - const discount = Math.round(price * c.discount * 100) / 100; + const discount = Math.round(price * (c.discount || 0) * 100) / 100; const vat = Math.round((price - discount) * c.vat * 100) / 100; a.totalPrice += price; @@ -525,7 +523,7 @@ export class QuotationController extends Controller { serviceId: v.serviceId, pricePerUnit: v.pricePerUnit || product.find((p) => p.id === v.productId)?.price || 0, amount: v.amount, - discount: v.discount, + discount: v.discount || 0, vat: v.vat || VAT_DEFAULT, }));