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 },
|
||||
data: {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -454,7 +454,7 @@ export class QuotationController extends Controller {
|
|||
|
||||
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 lastEmployee = await tx.runningNo.upsert({
|
||||
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}")
|
||||
|
|
|
|||
|
|
@ -268,13 +268,23 @@ export class RequestDataActionController extends Controller {
|
|||
}),
|
||||
]);
|
||||
await Promise.all([
|
||||
tx.quotation.updateMany({
|
||||
tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
requestData: {
|
||||
every: { requestDataStatus: RequestDataStatus.Canceled },
|
||||
},
|
||||
},
|
||||
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({
|
||||
where: {
|
||||
|
|
@ -405,13 +415,24 @@ export class RequestDataActionController extends Controller {
|
|||
data: { taskStatus: TaskStatus.Canceled },
|
||||
});
|
||||
await Promise.all([
|
||||
tx.quotation.updateMany({
|
||||
tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
quotationStatus: { not: QuotationStatus.Canceled },
|
||||
requestData: {
|
||||
every: { requestDataStatus: RequestDataStatus.Canceled },
|
||||
},
|
||||
},
|
||||
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({
|
||||
where: {
|
||||
|
|
@ -479,7 +500,8 @@ export class RequestDataActionController extends Controller {
|
|||
where: { id: { in: completed } },
|
||||
data: { requestDataStatus: RequestDataStatus.Completed },
|
||||
});
|
||||
await tx.quotation.updateMany({
|
||||
await tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
quotationStatus: {
|
||||
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
||||
|
|
@ -493,6 +515,15 @@ export class RequestDataActionController extends Controller {
|
|||
},
|
||||
},
|
||||
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);
|
||||
return data;
|
||||
|
|
@ -812,13 +843,24 @@ export class RequestListController extends Controller {
|
|||
data: { taskStatus: TaskStatus.Canceled },
|
||||
});
|
||||
await Promise.all([
|
||||
tx.quotation.updateMany({
|
||||
tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
quotationStatus: { not: QuotationStatus.Canceled },
|
||||
requestData: {
|
||||
every: { requestDataStatus: RequestDataStatus.Canceled },
|
||||
},
|
||||
},
|
||||
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({
|
||||
where: {
|
||||
|
|
@ -887,19 +929,32 @@ export class RequestListController extends Controller {
|
|||
where: { id: { in: completed } },
|
||||
data: { requestDataStatus: RequestDataStatus.Completed },
|
||||
});
|
||||
await tx.quotation.updateMany({
|
||||
await tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
quotationStatus: {
|
||||
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
||||
},
|
||||
requestData: {
|
||||
every: {
|
||||
requestDataStatus: { in: [RequestDataStatus.Canceled, RequestDataStatus.Completed] },
|
||||
requestDataStatus: {
|
||||
in: [RequestDataStatus.Canceled, RequestDataStatus.Completed],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -785,18 +785,30 @@ export class TaskActionController extends Controller {
|
|||
where: { id: { in: completed } },
|
||||
data: { requestDataStatus: RequestDataStatus.Completed },
|
||||
});
|
||||
await tx.quotation.updateMany({
|
||||
await tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
quotationStatus: {
|
||||
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
||||
},
|
||||
requestData: {
|
||||
every: {
|
||||
requestDataStatus: { in: [RequestDataStatus.Canceled, RequestDataStatus.Completed] },
|
||||
requestDataStatus: {
|
||||
in: [RequestDataStatus.Canceled, RequestDataStatus.Completed],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
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