refactor: make field optional

This commit is contained in:
Methapon Metanipat 2024-10-03 13:59:46 +07:00
parent 6faf4694e2
commit 7f9112c866

View file

@ -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,
}));