feat: add reject request cancel endpoint
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 8s

This commit is contained in:
Methapon2001 2025-03-12 16:36:39 +07:00
parent e76abd787c
commit b64cd5d1a6
3 changed files with 72 additions and 2 deletions

View file

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

View file

@ -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) {

View file

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