feat: add request work status

This commit is contained in:
Methapon Metanipat 2024-11-19 13:48:45 +07:00
parent 0d6fa7f7ba
commit fcb2e97b45
3 changed files with 43 additions and 25 deletions

View file

@ -1431,10 +1431,20 @@ model RequestWork {
productService QuotationProductServiceList @relation(fields: [productServiceId], references: [id], onDelete: Cascade)
productServiceId String
workStatus RequestWorkStatus @default(Pending)
processByUser User? @relation(fields: [processByUserId], references: [id])
processByUserId String?
attributes Json?
stepStatus RequestWorkStepStatus[]
}
model RequestWorkStepStatus {
step Int
workStatus RequestWorkStatus @default(Pending)
requestWork RequestWork @relation(fields: [requestWorkId], references: [id])
requestWorkId String
@@id([step, requestWorkId])
}

View file

@ -343,12 +343,7 @@ export class QuotationController extends Controller {
tx.employee.findMany({ where: { id: { in: ids.employee } } }),
tx.product.findMany({ where: { id: { in: ids.product } } }),
ids.work.length ? tx.work.findMany({ where: { id: { in: ids.work } } }) : null,
ids.service.length
? tx.service.findMany({
include: { work: { include: { productOnWork: true } } },
where: { id: { in: ids.service } },
})
: null,
ids.service.length ? tx.service.findMany({ where: { id: { in: ids.service } } }) : null,
]),
);
@ -430,13 +425,6 @@ export class QuotationController extends Controller {
amount: v.amount,
discount: v.discount || 0,
installmentNo: v.installmentNo,
attributes: service
?.find((s) => s.id === v.serviceId)
?.work.find((w) => w.id === v.workId)
?.productOnWork.find((p) => p.productId === v.productId)?.attributes as Record<
string,
unknown
>,
vat,
worker: {
create: sortedEmployeeId
@ -675,7 +663,6 @@ export class QuotationController extends Controller {
const vat = p.calcVat
? precisionRound((pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT)
: 0;
return {
order: i + 1,
productId: v.productId,
@ -686,13 +673,6 @@ export class QuotationController extends Controller {
discount: v.discount || 0,
installmentNo: v.installmentNo,
vat,
attributes: service
?.find((s) => s.id === v.serviceId)
?.work.find((w) => w.id === v.workId)
?.productOnWork.find((p) => p.productId === v.productId)?.attributes as Record<
string,
unknown
>,
worker: {
create: sortedEmployeeId
.filter((_, i) => !v.workerIndex || i in v.workerIndex)

View file

@ -152,6 +152,7 @@ export class RequestListController extends Controller {
employee: true,
},
},
stepStatus: true,
productService: {
include: {
service: true,
@ -194,6 +195,7 @@ export class RequestListController extends Controller {
employee: true,
},
},
stepStatus: true,
productService: {
include: {
service: true,
@ -221,15 +223,15 @@ export class RequestListController extends Controller {
}
@Put("{requestWorkId}")
@Security("keycloak")
async updateRequestWorkById(
@Request() req: RequestWithUser,
@Path() requestWorkId: string,
@Body() payload: { status: RequestWorkStatus; attributes: Record<string, any> },
@Body() payload: { attributes: Record<string, any> },
) {
const record = await prisma.requestWork.update({
where: { id: requestWorkId },
data: {
workStatus: payload.status,
request: {
update: { flow: payload.attributes },
},
@ -238,6 +240,32 @@ export class RequestListController extends Controller {
return record;
}
@Put("{requestWorkId}/step-status/{step}")
@Security("keycloak")
async updateRequestWorkStepStatus(
@Path() requestWorkId: string,
@Path() step: number,
@Body() payload: { requestWorkStatus: RequestWorkStatus },
) {
const record = await prisma.requestWorkStepStatus.upsert({
where: {
step_requestWorkId: {
step: step,
requestWorkId,
},
},
create: {
step: step,
requestWorkId,
workStatus: payload.requestWorkStatus,
},
update: {
workStatus: payload.requestWorkStatus,
},
});
return record;
}
}
export class RequestListAttachmentController extends Controller {}