refactor: make field optional
This commit is contained in:
parent
6faf4694e2
commit
7f9112c866
1 changed files with 4 additions and 6 deletions
|
|
@ -15,8 +15,6 @@ import {
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { RequestWithUser } from "../interfaces/user";
|
import { RequestWithUser } from "../interfaces/user";
|
||||||
import prisma from "../db";
|
import prisma from "../db";
|
||||||
import HttpError from "../interfaces/http-error";
|
|
||||||
import HttpStatus from "../interfaces/http-status";
|
|
||||||
import {
|
import {
|
||||||
branchRelationPermInclude,
|
branchRelationPermInclude,
|
||||||
createPermCheck,
|
createPermCheck,
|
||||||
|
|
@ -73,7 +71,7 @@ type QuotationCreate = {
|
||||||
* @maximum 1
|
* @maximum 1
|
||||||
* @minimum 0
|
* @minimum 0
|
||||||
*/
|
*/
|
||||||
discount: number;
|
discount?: number;
|
||||||
pricePerUnit?: number;
|
pricePerUnit?: number;
|
||||||
/**
|
/**
|
||||||
* @maximum 1
|
* @maximum 1
|
||||||
|
|
@ -332,14 +330,14 @@ export class QuotationController extends Controller {
|
||||||
serviceId: v.serviceId,
|
serviceId: v.serviceId,
|
||||||
pricePerUnit: v.pricePerUnit || product.find((p) => p.id === v.productId)?.price || 0,
|
pricePerUnit: v.pricePerUnit || product.find((p) => p.id === v.productId)?.price || 0,
|
||||||
amount: v.amount,
|
amount: v.amount,
|
||||||
discount: v.discount,
|
discount: v.discount || 0,
|
||||||
vat: v.vat || VAT_DEFAULT,
|
vat: v.vat || VAT_DEFAULT,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const price = list.reduce(
|
const price = list.reduce(
|
||||||
(a, c) => {
|
(a, c) => {
|
||||||
const price = c.pricePerUnit * c.amount;
|
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;
|
const vat = Math.round((price - discount) * c.vat * 100) / 100;
|
||||||
|
|
||||||
a.totalPrice += price;
|
a.totalPrice += price;
|
||||||
|
|
@ -525,7 +523,7 @@ export class QuotationController extends Controller {
|
||||||
serviceId: v.serviceId,
|
serviceId: v.serviceId,
|
||||||
pricePerUnit: v.pricePerUnit || product.find((p) => p.id === v.productId)?.price || 0,
|
pricePerUnit: v.pricePerUnit || product.find((p) => p.id === v.productId)?.price || 0,
|
||||||
amount: v.amount,
|
amount: v.amount,
|
||||||
discount: v.discount,
|
discount: v.discount || 0,
|
||||||
vat: v.vat || VAT_DEFAULT,
|
vat: v.vat || VAT_DEFAULT,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue