diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 671b21d..520410c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1442,6 +1442,9 @@ model RequestData { requestDataStatus RequestDataStatus @default(Pending) + customerRequestCancel Boolean? + customerRequestCancelReason String? + flow Json? requestWork RequestWork[] @@ -1477,6 +1480,9 @@ model RequestWork { stepStatus RequestWorkStepStatus[] + customerRequestCancel Boolean? + customerRequestCancelReason String? + creditNote CreditNote? @relation(fields: [creditNoteId], references: [id], onDelete: SetNull) creditNoteId String? } diff --git a/src/controllers/09-line-controller.ts b/src/controllers/09-line-controller.ts index 7704c4d..4e4910d 100644 --- a/src/controllers/09-line-controller.ts +++ b/src/controllers/09-line-controller.ts @@ -1,9 +1,11 @@ import { + Body, Controller, Delete, Get, Head, Path, + Post, Put, Query, Request, @@ -776,6 +778,70 @@ export class LineController extends Controller { return record; } + + @Post("request/{requestDataId}/request-cancel") + @Security("line") + async customerRequestCancel( + @Path() requestDataId: string, + @Request() req: RequestWithLineUser, + @Body() body: { reason: string }, + ) { + const result = await prisma.requestData.updateMany({ + where: { + id: requestDataId, + quotation: { + customerBranch: { + OR: [ + { userId: req.user.sub }, + { + customer: { + branch: { some: { userId: req.user.sub } }, + }, + }, + ], + }, + }, + }, + data: { + customerRequestCancel: true, + customerRequestCancelReason: body.reason, + }, + }); + if (result.count <= 0) throw notFoundError("Request Data"); + } + + @Post("request-work/{requestWorkId}/request-cancel") + @Security("line") + async customerRequestCancelWork( + @Path() requestWorkId: string, + @Request() req: RequestWithLineUser, + @Body() body: { reason: string }, + ) { + const result = await prisma.requestWork.updateMany({ + where: { + id: requestWorkId, + request: { + quotation: { + customerBranch: { + OR: [ + { userId: req.user.sub }, + { + customer: { + branch: { some: { userId: req.user.sub } }, + }, + }, + ], + }, + }, + }, + }, + data: { + customerRequestCancel: true, + customerRequestCancelReason: body.reason, + }, + }); + if (result.count <= 0) throw notFoundError("Request Data"); + } } @Route("api/v1/line/customer-branch/{branchId}")