feat: add quotation endpoint (complete)
This commit is contained in:
parent
7d7ac384c3
commit
0bcb69b09f
1 changed files with 11 additions and 13 deletions
|
|
@ -259,6 +259,13 @@ export class QuotationController extends Controller {
|
|||
"relationProductNotFound",
|
||||
);
|
||||
}
|
||||
if (existingEmployee.length !== employee.length) {
|
||||
throw new HttpError(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
"Some worker(employee) cannot be found.",
|
||||
"relationWorkerNotFound",
|
||||
);
|
||||
}
|
||||
if (!customer)
|
||||
throw new HttpError(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
|
|
@ -280,7 +287,7 @@ export class QuotationController extends Controller {
|
|||
|
||||
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 lastEmployee = await tx.runningNo.upsert({
|
||||
where: {
|
||||
|
|
@ -351,7 +358,6 @@ export class QuotationController extends Controller {
|
|||
100,
|
||||
) / 100;
|
||||
|
||||
console.log(e.vat);
|
||||
return {
|
||||
...e,
|
||||
vat: e.vat === undefined ? 0.07 : e.vat,
|
||||
|
|
@ -404,9 +410,8 @@ export class QuotationController extends Controller {
|
|||
|
||||
await Promise.all(
|
||||
restructureService.map(async (a) => {
|
||||
await tx.quotationService.create({
|
||||
const { id: _currentServiceId } = await tx.quotationService.create({
|
||||
data: {
|
||||
id: a.id,
|
||||
code: a.code,
|
||||
name: a.name,
|
||||
detail: a.detail,
|
||||
|
|
@ -419,11 +424,10 @@ export class QuotationController extends Controller {
|
|||
a.work.map(async (b) => {
|
||||
await tx.quotationServiceWork.create({
|
||||
data: {
|
||||
id: b.id,
|
||||
order: b.order,
|
||||
name: b.name,
|
||||
attributes: b.attributes,
|
||||
serviceId: a.id,
|
||||
serviceId: _currentServiceId,
|
||||
productOnWork: {
|
||||
createMany: {
|
||||
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: {
|
||||
service: {
|
||||
include: {
|
||||
|
|
@ -467,12 +471,6 @@ export class QuotationController extends Controller {
|
|||
},
|
||||
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("");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue