diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2286ca9..acc8cec 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1464,6 +1464,8 @@ model RequestData { customerRequestCancel Boolean? customerRequestCancelReason String? + rejectRequestCancel Boolean? + rejectRequestCancelReason String? flow Json? @@ -1502,6 +1504,8 @@ model RequestWork { customerRequestCancel Boolean? customerRequestCancelReason String? + rejectRequestCancel Boolean? + rejectRequestCancelReason String? creditNote CreditNote? @relation(fields: [creditNoteId], references: [id], onDelete: SetNull) creditNoteId String? diff --git a/src/controllers/06-request-list-controller.ts b/src/controllers/06-request-list-controller.ts index b0d78e9..bfd9712 100644 --- a/src/controllers/06-request-list-controller.ts +++ b/src/controllers/06-request-list-controller.ts @@ -239,6 +239,68 @@ export class RequestDataController extends Controller { @Route("/api/v1/request-data/{requestDataId}") @Tags("Request List") export class RequestDataActionController extends Controller { + @Post("reject-request-cancel") + @Security("keycloak") + async rejectRequestCancel( + @Request() req: RequestWithUser, + @Path() requestDataId: string, + @Body() + body: { + reason?: string; + }, + ) { + const result = await prisma.requestData.updateManyAndReturn({ + where: { + id: requestDataId, + quotation: { + registeredBranch: { + OR: permissionCond(req.user), + }, + }, + }, + data: { + rejectRequestCancel: true, + rejectRequestCancelReason: body.reason || "", + }, + }); + + if (result.length <= 0) throw notFoundError("Request Data"); + + return result[0]; + } + + @Post("request-work/${requestWorkId}/reject-request-cancel") + @Security("keycloak") + async rejectWorkRequestCancel( + @Request() req: RequestWithUser, + @Path() requestWorkId: string, + @Body() + body: { + reason?: string; + }, + ) { + const result = await prisma.requestWork.updateManyAndReturn({ + where: { + id: requestWorkId, + request: { + quotation: { + registeredBranch: { + OR: permissionCond(req.user), + }, + }, + }, + }, + data: { + rejectRequestCancel: true, + rejectRequestCancelReason: body.reason || "", + }, + }); + + if (result.length <= 0) throw notFoundError("Request Data"); + + return result[0]; + } + @Post("cancel") @Security("keycloak") async cancelRequestData(@Path() requestDataId: string) { diff --git a/src/controllers/09-line-controller.ts b/src/controllers/09-line-controller.ts index 019d942..cf8d7f3 100644 --- a/src/controllers/09-line-controller.ts +++ b/src/controllers/09-line-controller.ts @@ -804,7 +804,9 @@ export class LineController extends Controller { }, data: { customerRequestCancel: body.cancel, - customerRequestCancelReason: body.reason || "", + customerRequestCancelReason: body.reason || null, + rejectRequestCancel: false, + rejectRequestCancelReason: null, }, }); if (result.count <= 0) throw notFoundError("Request Data"); @@ -837,7 +839,9 @@ export class LineController extends Controller { }, data: { customerRequestCancel: body.cancel, - customerRequestCancelReason: body.reason || "", + customerRequestCancelReason: body.reason || null, + rejectRequestCancel: false, + rejectRequestCancelReason: null, }, }); if (result.count <= 0) throw notFoundError("Request Data");