feat: check if request data is completed
This commit is contained in:
parent
37a9dd2677
commit
369d0f4696
1 changed files with 52 additions and 7 deletions
|
|
@ -421,7 +421,6 @@ export class RequestListController extends Controller {
|
|||
responsibleUserLocal?: boolean | null;
|
||||
responsibleUserId?: string | null;
|
||||
},
|
||||
@Query() successAll?: boolean,
|
||||
) {
|
||||
if (!payload.responsibleUserId) payload.responsibleUserId = undefined;
|
||||
|
||||
|
|
@ -458,14 +457,60 @@ export class RequestListController extends Controller {
|
|||
break;
|
||||
}
|
||||
|
||||
if (successAll && (payload.workStatus === "Completed" || payload.workStatus === "Ended")) {
|
||||
await prisma.requestData.update({
|
||||
where: {
|
||||
id: record.requestWork.requestDataId,
|
||||
await prisma.$transaction(async (tx) => {
|
||||
const requestList = await tx.requestData.findMany({
|
||||
include: {
|
||||
requestWork: {
|
||||
include: {
|
||||
productService: {
|
||||
include: {
|
||||
product: true,
|
||||
service: true,
|
||||
work: {
|
||||
include: { productOnWork: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
stepStatus: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
where: {
|
||||
requestWork: {
|
||||
some: {
|
||||
requestDataId: record.requestWork.requestDataId,
|
||||
},
|
||||
},
|
||||
},
|
||||
data: { requestDataStatus: "Completed" },
|
||||
});
|
||||
}
|
||||
|
||||
const completed: string[] = [];
|
||||
|
||||
requestList.forEach((item) => {
|
||||
const completeCheck = item.requestWork.every((work) => {
|
||||
const stepCount =
|
||||
work.productService.work?.productOnWork.find(
|
||||
(v) => v.productId === work.productService.productId,
|
||||
)?.stepCount || 0;
|
||||
|
||||
const completeCount = work.stepStatus.filter(
|
||||
(v) => v.workStatus === RequestWorkStatus.Completed,
|
||||
).length;
|
||||
|
||||
// NOTE: step found then check if complete count equals step count
|
||||
if (stepCount === completeCount && completeCount > 0) return true;
|
||||
// NOTE: likely no step found and completed at least one
|
||||
if (stepCount === 0 && completeCount > 0) return true;
|
||||
});
|
||||
|
||||
if (completeCheck) completed.push(item.id);
|
||||
});
|
||||
|
||||
await tx.requestData.updateMany({
|
||||
where: { id: { in: completed } },
|
||||
data: { requestDataStatus: RequestDataStatus.Completed },
|
||||
});
|
||||
});
|
||||
|
||||
return record;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue