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;
|
responsibleUserLocal?: boolean | null;
|
||||||
responsibleUserId?: string | null;
|
responsibleUserId?: string | null;
|
||||||
},
|
},
|
||||||
@Query() successAll?: boolean,
|
|
||||||
) {
|
) {
|
||||||
if (!payload.responsibleUserId) payload.responsibleUserId = undefined;
|
if (!payload.responsibleUserId) payload.responsibleUserId = undefined;
|
||||||
|
|
||||||
|
|
@ -458,14 +457,60 @@ export class RequestListController extends Controller {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (successAll && (payload.workStatus === "Completed" || payload.workStatus === "Ended")) {
|
await prisma.$transaction(async (tx) => {
|
||||||
await prisma.requestData.update({
|
const requestList = await tx.requestData.findMany({
|
||||||
where: {
|
include: {
|
||||||
id: record.requestWork.requestDataId,
|
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;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue