feat: add quotation endpoint (complete)

This commit is contained in:
Methapon2001 2024-07-23 11:24:07 +07:00
parent 7d7ac384c3
commit 0bcb69b09f

View file

@ -259,6 +259,13 @@ export class QuotationController extends Controller {
"relationProductNotFound", "relationProductNotFound",
); );
} }
if (existingEmployee.length !== employee.length) {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Some worker(employee) cannot be found.",
"relationWorkerNotFound",
);
}
if (!customer) if (!customer)
throw new HttpError( throw new HttpError(
HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST,
@ -280,7 +287,7 @@ export class QuotationController extends Controller {
const { service: _service, worker: _worker, ...rest } = body; const { service: _service, worker: _worker, ...rest } = body;
await prisma.$transaction(async (tx) => { return await prisma.$transaction(async (tx) => {
const nonExistEmployee = body.worker.filter((v) => typeof v !== "string"); const nonExistEmployee = body.worker.filter((v) => typeof v !== "string");
const lastEmployee = await tx.runningNo.upsert({ const lastEmployee = await tx.runningNo.upsert({
where: { where: {
@ -351,7 +358,6 @@ export class QuotationController extends Controller {
100, 100,
) / 100; ) / 100;
console.log(e.vat);
return { return {
...e, ...e,
vat: e.vat === undefined ? 0.07 : e.vat, vat: e.vat === undefined ? 0.07 : e.vat,
@ -404,9 +410,8 @@ export class QuotationController extends Controller {
await Promise.all( await Promise.all(
restructureService.map(async (a) => { restructureService.map(async (a) => {
await tx.quotationService.create({ const { id: _currentServiceId } = await tx.quotationService.create({
data: { data: {
id: a.id,
code: a.code, code: a.code,
name: a.name, name: a.name,
detail: a.detail, detail: a.detail,
@ -419,11 +424,10 @@ export class QuotationController extends Controller {
a.work.map(async (b) => { a.work.map(async (b) => {
await tx.quotationServiceWork.create({ await tx.quotationServiceWork.create({
data: { data: {
id: b.id,
order: b.order, order: b.order,
name: b.name, name: b.name,
attributes: b.attributes, attributes: b.attributes,
serviceId: a.id, serviceId: _currentServiceId,
productOnWork: { productOnWork: {
createMany: { createMany: {
data: b.product.map((v, i) => ({ data: b.product.map((v, i) => ({
@ -443,7 +447,7 @@ export class QuotationController extends Controller {
}), }),
); );
const result = await tx.quotation.findUnique({ return await tx.quotation.findUnique({
include: { include: {
service: { service: {
include: { include: {
@ -467,12 +471,6 @@ export class QuotationController extends Controller {
}, },
where: { id: quotation.id }, where: { id: quotation.id },
}); });
console.log(JSON.stringify(result, null, 2));
// console.log("Re-Structure:", JSON.stringify(restructureService, null, 2));
// console.log("Price:", JSON.stringify(price, null, 2));
throw new Error("");
}); });
} }