feat: notify request, task update
This commit is contained in:
parent
afb4a83efa
commit
17b92b4012
2 changed files with 137 additions and 105 deletions
|
|
@ -1136,41 +1136,53 @@ export class QuotationActionController extends Controller {
|
||||||
},
|
},
|
||||||
update: { value: { increment: quotation.worker.length } },
|
update: { value: { increment: quotation.worker.length } },
|
||||||
});
|
});
|
||||||
await tx.quotation.update({
|
await tx.quotation
|
||||||
where: { id: quotationId, isDebitNote: false },
|
.update({
|
||||||
data: {
|
include: { requestData: true },
|
||||||
quotationStatus: QuotationStatus.PaymentSuccess, // NOTE: change back if already complete or canceled
|
where: { id: quotationId, isDebitNote: false },
|
||||||
worker: {
|
data: {
|
||||||
createMany: {
|
quotationStatus: QuotationStatus.PaymentSuccess, // NOTE: change back if already complete or canceled
|
||||||
data: rearrange
|
worker: {
|
||||||
.filter((lhs) => !quotation.worker.find((rhs) => rhs.employeeId === lhs.workerId))
|
createMany: {
|
||||||
.map((v, i) => ({
|
data: rearrange
|
||||||
no: quotation._count.worker + i + 1,
|
.filter((lhs) => !quotation.worker.find((rhs) => rhs.employeeId === lhs.workerId))
|
||||||
employeeId: v.workerId,
|
.map((v, i) => ({
|
||||||
})),
|
no: quotation._count.worker + i + 1,
|
||||||
|
employeeId: v.workerId,
|
||||||
|
})),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
requestData:
|
||||||
|
quotation.quotationStatus === "PaymentInProcess" ||
|
||||||
|
quotation.quotationStatus === "PaymentSuccess"
|
||||||
|
? {
|
||||||
|
create: rearrange
|
||||||
|
.filter(
|
||||||
|
(lhs) =>
|
||||||
|
!quotation.worker.find((rhs) => rhs.employeeId === lhs.workerId) &&
|
||||||
|
lhs.productServiceId.length > 0,
|
||||||
|
)
|
||||||
|
.map((v, i) => ({
|
||||||
|
code: `TR${year}${month}${(lastRequest.value - quotation._count.worker + i + 1).toString().padStart(6, "0")}`,
|
||||||
|
employeeId: v.workerId,
|
||||||
|
requestWork: {
|
||||||
|
create: v.productServiceId.map((v) => ({ productServiceId: v })),
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
},
|
},
|
||||||
requestData:
|
})
|
||||||
quotation.quotationStatus === "PaymentInProcess" ||
|
.then(async (ret) => {
|
||||||
quotation.quotationStatus === "PaymentSuccess"
|
await prisma.notification.create({
|
||||||
? {
|
data: {
|
||||||
create: rearrange
|
title: "New Request",
|
||||||
.filter(
|
detail: "New request: " + ret.requestData.map((v) => v.code).join(", "),
|
||||||
(lhs) =>
|
registeredBranchId: ret.registeredBranchId,
|
||||||
!quotation.worker.find((rhs) => rhs.employeeId === lhs.workerId) &&
|
groupReceiver: { create: { name: "document_checker" } },
|
||||||
lhs.productServiceId.length > 0,
|
},
|
||||||
)
|
});
|
||||||
.map((v, i) => ({
|
});
|
||||||
code: `TR${year}${month}${(lastRequest.value - quotation._count.worker + i + 1).toString().padStart(6, "0")}`,
|
|
||||||
employeeId: v.workerId,
|
|
||||||
requestWork: {
|
|
||||||
create: v.productServiceId.map((v) => ({ productServiceId: v })),
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -433,88 +433,101 @@ export class TaskController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await prisma.$transaction(async (tx) => {
|
return await prisma
|
||||||
await Promise.all(
|
.$transaction(async (tx) => {
|
||||||
record.taskList
|
await Promise.all(
|
||||||
.filter(
|
record.taskList
|
||||||
(lhs) =>
|
.filter(
|
||||||
!body.taskList.find(
|
(lhs) =>
|
||||||
(rhs) => lhs.requestWorkId === rhs.requestWorkId && lhs.step === rhs.step,
|
!body.taskList.find(
|
||||||
),
|
(rhs) => lhs.requestWorkId === rhs.requestWorkId && lhs.step === rhs.step,
|
||||||
)
|
),
|
||||||
.map((v) =>
|
)
|
||||||
tx.task.update({
|
.map((v) =>
|
||||||
where: { id: v.id },
|
tx.task.update({
|
||||||
data: {
|
where: { id: v.id },
|
||||||
requestWorkStep: { update: { workStatus: "Ready" } },
|
data: {
|
||||||
},
|
requestWorkStep: { update: { workStatus: "Ready" } },
|
||||||
}),
|
},
|
||||||
),
|
}),
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
|
||||||
await tx.requestWorkStepStatus.updateMany({
|
await tx.requestWorkStepStatus.updateMany({
|
||||||
where: {
|
where: {
|
||||||
OR: body.taskList,
|
OR: body.taskList,
|
||||||
workStatus: RequestWorkStatus.Ready,
|
workStatus: RequestWorkStatus.Ready,
|
||||||
},
|
|
||||||
data: { workStatus: RequestWorkStatus.InProgress },
|
|
||||||
});
|
|
||||||
|
|
||||||
const work = await tx.requestWorkStepStatus.findMany({
|
|
||||||
include: {
|
|
||||||
requestWork: {
|
|
||||||
include: {
|
|
||||||
request: {
|
|
||||||
include: { quotation: true },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
data: { workStatus: RequestWorkStatus.InProgress },
|
||||||
where: { OR: body.taskList },
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return await tx.taskOrder.update({
|
const work = await tx.requestWorkStepStatus.findMany({
|
||||||
where: { id: taskOrderId },
|
include: {
|
||||||
include: {
|
requestWork: {
|
||||||
taskList: {
|
include: {
|
||||||
include: {
|
request: {
|
||||||
requestWorkStep: {
|
include: { quotation: true },
|
||||||
include: {
|
|
||||||
requestWork: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
institution: true,
|
where: { OR: body.taskList },
|
||||||
registeredBranch: true,
|
});
|
||||||
createdBy: true,
|
|
||||||
},
|
return await tx.taskOrder.update({
|
||||||
data: {
|
where: { id: taskOrderId },
|
||||||
...body,
|
include: {
|
||||||
urgent: work.some((v) => v.requestWork.request.quotation.urgent),
|
taskList: {
|
||||||
taskList: {
|
include: {
|
||||||
deleteMany: record?.taskList
|
requestWorkStep: {
|
||||||
.filter(
|
include: {
|
||||||
(lhs) =>
|
requestWork: true,
|
||||||
!body.taskList.find(
|
},
|
||||||
(rhs) => lhs.requestWorkId === rhs.requestWorkId && lhs.step === rhs.step,
|
},
|
||||||
),
|
},
|
||||||
)
|
|
||||||
.map((v) => ({ id: v.id })),
|
|
||||||
createMany: {
|
|
||||||
data: body.taskList.filter(
|
|
||||||
(lhs) =>
|
|
||||||
!record?.taskList.find(
|
|
||||||
(rhs) => lhs.requestWorkId === rhs.requestWorkId && lhs.step === rhs.step,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
skipDuplicates: true,
|
|
||||||
},
|
},
|
||||||
|
institution: true,
|
||||||
|
registeredBranch: true,
|
||||||
|
createdBy: true,
|
||||||
},
|
},
|
||||||
taskProduct: { deleteMany: {}, create: body.taskProduct },
|
data: {
|
||||||
},
|
...body,
|
||||||
|
urgent: work.some((v) => v.requestWork.request.quotation.urgent),
|
||||||
|
taskList: {
|
||||||
|
deleteMany: record?.taskList
|
||||||
|
.filter(
|
||||||
|
(lhs) =>
|
||||||
|
!body.taskList.find(
|
||||||
|
(rhs) => lhs.requestWorkId === rhs.requestWorkId && lhs.step === rhs.step,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.map((v) => ({ id: v.id })),
|
||||||
|
createMany: {
|
||||||
|
data: body.taskList.filter(
|
||||||
|
(lhs) =>
|
||||||
|
!record?.taskList.find(
|
||||||
|
(rhs) => lhs.requestWorkId === rhs.requestWorkId && lhs.step === rhs.step,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
skipDuplicates: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
taskProduct: { deleteMany: {}, create: body.taskProduct },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(async (ret) => {
|
||||||
|
if (body.taskOrderStatus && record.taskOrderStatus !== body.taskOrderStatus) {
|
||||||
|
await prisma.notification.create({
|
||||||
|
data: {
|
||||||
|
title: "Task Submitted",
|
||||||
|
detail: "Task submitted in order: " + record.code,
|
||||||
|
receiverId: record.createdByUserId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("{taskOrderId}")
|
@Delete("{taskOrderId}")
|
||||||
|
|
@ -651,6 +664,13 @@ export class TaskActionController extends Controller {
|
||||||
},
|
},
|
||||||
data: { userTaskStatus: UserTaskStatus.Submit, submittedAt: new Date() },
|
data: { userTaskStatus: UserTaskStatus.Submit, submittedAt: new Date() },
|
||||||
}),
|
}),
|
||||||
|
prisma.notification.create({
|
||||||
|
data: {
|
||||||
|
title: "Task Submitted",
|
||||||
|
detail: "Task submitted in order: " + record.code,
|
||||||
|
receiverId: record.createdByUserId,
|
||||||
|
},
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue