diff --git a/src/controllers/06-request-list-controller.ts b/src/controllers/06-request-list-controller.ts index 764fbc7..a453716 100644 --- a/src/controllers/06-request-list-controller.ts +++ b/src/controllers/06-request-list-controller.ts @@ -293,28 +293,48 @@ export class RequestDataController extends Controller { async updateRequestData( @Request() req: RequestWithUser, @Body() - boby: { + body: { defaultMessengerId: string; requestDataId: string[]; }, ) { - const record = await prisma.requestData.updateManyAndReturn({ - where: { - id: { in: boby.requestDataId }, - quotation: { - registeredBranch: { - OR: permissionCond(req.user), + if (body.requestDataId.length === 0) return; + + return await prisma.$transaction(async (tx) => { + const record = await tx.requestData.updateManyAndReturn({ + where: { + id: { in: body.requestDataId }, + quotation: { + registeredBranch: { + OR: permissionCond(req.user), + }, }, }, - }, - data: { - defaultMessengerId: boby.defaultMessengerId, - }, + data: { + defaultMessengerId: body.defaultMessengerId, + }, + }); + + if (record.length <= 0) throw notFoundError("Request Data"); + + await tx.requestWorkStepStatus.updateMany({ + where: { + workStatus: { + in: [ + RequestWorkStatus.Pending, + RequestWorkStatus.Waiting, + RequestWorkStatus.InProgress, + ], + }, + requestWork: { + requestDataId: { in: body.requestDataId }, + }, + }, + data: { responsibleUserId: body.defaultMessengerId }, + }); + + return record[0]; }); - - if (record.length <= 0) throw notFoundError("Request Data"); - - return record[0]; } }