feat: add request work status
This commit is contained in:
parent
0d6fa7f7ba
commit
fcb2e97b45
3 changed files with 43 additions and 25 deletions
|
|
@ -1431,10 +1431,20 @@ model RequestWork {
|
||||||
productService QuotationProductServiceList @relation(fields: [productServiceId], references: [id], onDelete: Cascade)
|
productService QuotationProductServiceList @relation(fields: [productServiceId], references: [id], onDelete: Cascade)
|
||||||
productServiceId String
|
productServiceId String
|
||||||
|
|
||||||
workStatus RequestWorkStatus @default(Pending)
|
|
||||||
|
|
||||||
processByUser User? @relation(fields: [processByUserId], references: [id])
|
processByUser User? @relation(fields: [processByUserId], references: [id])
|
||||||
processByUserId String?
|
processByUserId String?
|
||||||
|
|
||||||
attributes Json?
|
attributes Json?
|
||||||
|
|
||||||
|
stepStatus RequestWorkStepStatus[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model RequestWorkStepStatus {
|
||||||
|
step Int
|
||||||
|
workStatus RequestWorkStatus @default(Pending)
|
||||||
|
|
||||||
|
requestWork RequestWork @relation(fields: [requestWorkId], references: [id])
|
||||||
|
requestWorkId String
|
||||||
|
|
||||||
|
@@id([step, requestWorkId])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -343,12 +343,7 @@ export class QuotationController extends Controller {
|
||||||
tx.employee.findMany({ where: { id: { in: ids.employee } } }),
|
tx.employee.findMany({ where: { id: { in: ids.employee } } }),
|
||||||
tx.product.findMany({ where: { id: { in: ids.product } } }),
|
tx.product.findMany({ where: { id: { in: ids.product } } }),
|
||||||
ids.work.length ? tx.work.findMany({ where: { id: { in: ids.work } } }) : null,
|
ids.work.length ? tx.work.findMany({ where: { id: { in: ids.work } } }) : null,
|
||||||
ids.service.length
|
ids.service.length ? tx.service.findMany({ where: { id: { in: ids.service } } }) : null,
|
||||||
? tx.service.findMany({
|
|
||||||
include: { work: { include: { productOnWork: true } } },
|
|
||||||
where: { id: { in: ids.service } },
|
|
||||||
})
|
|
||||||
: null,
|
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -430,13 +425,6 @@ export class QuotationController extends Controller {
|
||||||
amount: v.amount,
|
amount: v.amount,
|
||||||
discount: v.discount || 0,
|
discount: v.discount || 0,
|
||||||
installmentNo: v.installmentNo,
|
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,
|
vat,
|
||||||
worker: {
|
worker: {
|
||||||
create: sortedEmployeeId
|
create: sortedEmployeeId
|
||||||
|
|
@ -675,7 +663,6 @@ export class QuotationController extends Controller {
|
||||||
const vat = p.calcVat
|
const vat = p.calcVat
|
||||||
? precisionRound((pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT)
|
? precisionRound((pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
order: i + 1,
|
order: i + 1,
|
||||||
productId: v.productId,
|
productId: v.productId,
|
||||||
|
|
@ -686,13 +673,6 @@ export class QuotationController extends Controller {
|
||||||
discount: v.discount || 0,
|
discount: v.discount || 0,
|
||||||
installmentNo: v.installmentNo,
|
installmentNo: v.installmentNo,
|
||||||
vat,
|
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: {
|
worker: {
|
||||||
create: sortedEmployeeId
|
create: sortedEmployeeId
|
||||||
.filter((_, i) => !v.workerIndex || i in v.workerIndex)
|
.filter((_, i) => !v.workerIndex || i in v.workerIndex)
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,7 @@ export class RequestListController extends Controller {
|
||||||
employee: true,
|
employee: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
stepStatus: true,
|
||||||
productService: {
|
productService: {
|
||||||
include: {
|
include: {
|
||||||
service: true,
|
service: true,
|
||||||
|
|
@ -194,6 +195,7 @@ export class RequestListController extends Controller {
|
||||||
employee: true,
|
employee: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
stepStatus: true,
|
||||||
productService: {
|
productService: {
|
||||||
include: {
|
include: {
|
||||||
service: true,
|
service: true,
|
||||||
|
|
@ -221,15 +223,15 @@ export class RequestListController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("{requestWorkId}")
|
@Put("{requestWorkId}")
|
||||||
|
@Security("keycloak")
|
||||||
async updateRequestWorkById(
|
async updateRequestWorkById(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Path() requestWorkId: string,
|
@Path() requestWorkId: string,
|
||||||
@Body() payload: { status: RequestWorkStatus; attributes: Record<string, any> },
|
@Body() payload: { attributes: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const record = await prisma.requestWork.update({
|
const record = await prisma.requestWork.update({
|
||||||
where: { id: requestWorkId },
|
where: { id: requestWorkId },
|
||||||
data: {
|
data: {
|
||||||
workStatus: payload.status,
|
|
||||||
request: {
|
request: {
|
||||||
update: { flow: payload.attributes },
|
update: { flow: payload.attributes },
|
||||||
},
|
},
|
||||||
|
|
@ -238,6 +240,32 @@ export class RequestListController extends Controller {
|
||||||
|
|
||||||
return record;
|
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 {}
|
export class RequestListAttachmentController extends Controller {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue