From 1f2a0639748765d811844ab620ad5355334e46ee Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 5 Mar 2025 09:33:06 +0700 Subject: [PATCH 1/2] feat: add request cancel field --- prisma/schema.prisma | 6 ++++++ 1 file changed, 6 insertions(+) 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? } From 57641681ea8982a38f917a8cc5cb296294eb1b4c Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 5 Mar 2025 11:37:25 +0700 Subject: [PATCH 2/2] feat: add customer request cancel detail --- src/controllers/09-line-controller.ts | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) 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}")