feat: notify quotation status change
This commit is contained in:
parent
071262a85a
commit
2697b4f6e0
4 changed files with 192 additions and 103 deletions
|
|
@ -177,7 +177,8 @@ export class QuotationPayment extends Controller {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await tx.quotation.update({
|
await tx.quotation
|
||||||
|
.update({
|
||||||
where: { id: quotation.id },
|
where: { id: quotation.id },
|
||||||
data: {
|
data: {
|
||||||
quotationStatus:
|
quotationStatus:
|
||||||
|
|
@ -225,6 +226,16 @@ export class QuotationPayment extends Controller {
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
},
|
},
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
if (quotation.quotationStatus !== res.quotationStatus)
|
||||||
|
await tx.notification.create({
|
||||||
|
data: {
|
||||||
|
title: "Quotation Status Updated",
|
||||||
|
detail: res.code + res.quotationStatus,
|
||||||
|
receiverId: res.createdByUserId,
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return payment;
|
return payment;
|
||||||
|
|
|
||||||
|
|
@ -454,7 +454,7 @@ export class QuotationController extends Controller {
|
||||||
|
|
||||||
const { productServiceList: _productServiceList, worker: _worker, ...rest } = body;
|
const { productServiceList: _productServiceList, worker: _worker, ...rest } = body;
|
||||||
|
|
||||||
return await prisma.$transaction(async (tx) => {
|
const ret = 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: {
|
||||||
|
|
@ -639,6 +639,17 @@ export class QuotationController extends Controller {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await prisma.notification.create({
|
||||||
|
data: {
|
||||||
|
title: "New Quotation",
|
||||||
|
detail: "New quotation: " + ret.code,
|
||||||
|
registeredBranchId: ret.registeredBranchId,
|
||||||
|
groupReceiver: { create: [{ name: "accountant" }, { name: "head_of_accountant" }] },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("{quotationId}")
|
@Put("{quotationId}")
|
||||||
|
|
|
||||||
|
|
@ -268,13 +268,23 @@ export class RequestDataActionController extends Controller {
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
tx.quotation.updateMany({
|
tx.quotation
|
||||||
|
.updateManyAndReturn({
|
||||||
where: {
|
where: {
|
||||||
requestData: {
|
requestData: {
|
||||||
every: { requestDataStatus: RequestDataStatus.Canceled },
|
every: { requestDataStatus: RequestDataStatus.Canceled },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: { quotationStatus: QuotationStatus.Canceled, urgent: false },
|
data: { quotationStatus: QuotationStatus.Canceled, urgent: false },
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
await tx.notification.createMany({
|
||||||
|
data: res.map((v) => ({
|
||||||
|
title: "Quotation Status Updated",
|
||||||
|
detail: v.code + "Canceled",
|
||||||
|
receiverId: v.createdByUserId,
|
||||||
|
})),
|
||||||
|
});
|
||||||
}),
|
}),
|
||||||
tx.taskOrder.updateMany({
|
tx.taskOrder.updateMany({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -405,13 +415,24 @@ export class RequestDataActionController extends Controller {
|
||||||
data: { taskStatus: TaskStatus.Canceled },
|
data: { taskStatus: TaskStatus.Canceled },
|
||||||
});
|
});
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
tx.quotation.updateMany({
|
tx.quotation
|
||||||
|
.updateManyAndReturn({
|
||||||
where: {
|
where: {
|
||||||
|
quotationStatus: { not: QuotationStatus.Canceled },
|
||||||
requestData: {
|
requestData: {
|
||||||
every: { requestDataStatus: RequestDataStatus.Canceled },
|
every: { requestDataStatus: RequestDataStatus.Canceled },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: { quotationStatus: QuotationStatus.Canceled, urgent: false },
|
data: { quotationStatus: QuotationStatus.Canceled, urgent: false },
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
await tx.notification.createMany({
|
||||||
|
data: res.map((v) => ({
|
||||||
|
title: "Quotation Status Updated",
|
||||||
|
detail: v.code + "Canceled",
|
||||||
|
receiverId: v.createdByUserId,
|
||||||
|
})),
|
||||||
|
});
|
||||||
}),
|
}),
|
||||||
tx.taskOrder.updateMany({
|
tx.taskOrder.updateMany({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -479,7 +500,8 @@ export class RequestDataActionController extends Controller {
|
||||||
where: { id: { in: completed } },
|
where: { id: { in: completed } },
|
||||||
data: { requestDataStatus: RequestDataStatus.Completed },
|
data: { requestDataStatus: RequestDataStatus.Completed },
|
||||||
});
|
});
|
||||||
await tx.quotation.updateMany({
|
await tx.quotation
|
||||||
|
.updateManyAndReturn({
|
||||||
where: {
|
where: {
|
||||||
quotationStatus: {
|
quotationStatus: {
|
||||||
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
||||||
|
|
@ -493,6 +515,15 @@ export class RequestDataActionController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
await tx.notification.createMany({
|
||||||
|
data: res.map((v) => ({
|
||||||
|
title: "Quotation Status Updated",
|
||||||
|
detail: v.code + "Completed",
|
||||||
|
receiverId: v.createdByUserId,
|
||||||
|
})),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
// dataRecord.push(record);
|
// dataRecord.push(record);
|
||||||
return data;
|
return data;
|
||||||
|
|
@ -812,13 +843,24 @@ export class RequestListController extends Controller {
|
||||||
data: { taskStatus: TaskStatus.Canceled },
|
data: { taskStatus: TaskStatus.Canceled },
|
||||||
});
|
});
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
tx.quotation.updateMany({
|
tx.quotation
|
||||||
|
.updateManyAndReturn({
|
||||||
where: {
|
where: {
|
||||||
|
quotationStatus: { not: QuotationStatus.Canceled },
|
||||||
requestData: {
|
requestData: {
|
||||||
every: { requestDataStatus: RequestDataStatus.Canceled },
|
every: { requestDataStatus: RequestDataStatus.Canceled },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: { quotationStatus: QuotationStatus.Canceled, urgent: false },
|
data: { quotationStatus: QuotationStatus.Canceled, urgent: false },
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
await tx.notification.createMany({
|
||||||
|
data: res.map((v) => ({
|
||||||
|
title: "Quotation Status Updated",
|
||||||
|
detail: v.code + "Canceled",
|
||||||
|
receiverId: v.createdByUserId,
|
||||||
|
})),
|
||||||
|
});
|
||||||
}),
|
}),
|
||||||
tx.taskOrder.updateMany({
|
tx.taskOrder.updateMany({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -887,19 +929,32 @@ export class RequestListController extends Controller {
|
||||||
where: { id: { in: completed } },
|
where: { id: { in: completed } },
|
||||||
data: { requestDataStatus: RequestDataStatus.Completed },
|
data: { requestDataStatus: RequestDataStatus.Completed },
|
||||||
});
|
});
|
||||||
await tx.quotation.updateMany({
|
await tx.quotation
|
||||||
|
.updateManyAndReturn({
|
||||||
where: {
|
where: {
|
||||||
quotationStatus: {
|
quotationStatus: {
|
||||||
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
||||||
},
|
},
|
||||||
requestData: {
|
requestData: {
|
||||||
every: {
|
every: {
|
||||||
requestDataStatus: { in: [RequestDataStatus.Canceled, RequestDataStatus.Completed] },
|
requestDataStatus: {
|
||||||
|
in: [RequestDataStatus.Canceled, RequestDataStatus.Completed],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
await tx.notification.createMany({
|
||||||
|
data: res.map((v) => ({
|
||||||
|
title: "Quotation Status Updated",
|
||||||
|
detail: v.code + "Completed",
|
||||||
|
receiverId: v.createdByUserId,
|
||||||
|
})),
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -785,18 +785,30 @@ export class TaskActionController extends Controller {
|
||||||
where: { id: { in: completed } },
|
where: { id: { in: completed } },
|
||||||
data: { requestDataStatus: RequestDataStatus.Completed },
|
data: { requestDataStatus: RequestDataStatus.Completed },
|
||||||
});
|
});
|
||||||
await tx.quotation.updateMany({
|
await tx.quotation
|
||||||
|
.updateManyAndReturn({
|
||||||
where: {
|
where: {
|
||||||
quotationStatus: {
|
quotationStatus: {
|
||||||
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
||||||
},
|
},
|
||||||
requestData: {
|
requestData: {
|
||||||
every: {
|
every: {
|
||||||
requestDataStatus: { in: [RequestDataStatus.Canceled, RequestDataStatus.Completed] },
|
requestDataStatus: {
|
||||||
|
in: [RequestDataStatus.Canceled, RequestDataStatus.Completed],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
await tx.notification.createMany({
|
||||||
|
data: res.map((v) => ({
|
||||||
|
title: "Quotation Status Updated",
|
||||||
|
detail: v.code + "Completed",
|
||||||
|
receiverId: v.createdByUserId,
|
||||||
|
})),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue