Merge pull request #18 from Frappet/feat/customer-request-cancel
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 6s

feat: customer request cancel endpoint
This commit is contained in:
Methapon Metanipat 2025-03-05 11:38:56 +07:00 committed by GitHub
commit 1add3f3ba0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 72 additions and 0 deletions

View file

@ -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?
}

View file

@ -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}")