feat: add relation document to request work
This commit is contained in:
parent
20361c597d
commit
026bf44bc7
1 changed files with 34 additions and 4 deletions
|
|
@ -4,6 +4,7 @@ import prisma from "../db";
|
|||
import { Prisma, RequestDataStatus, RequestWorkStatus } from "@prisma/client";
|
||||
import { createPermCondition } from "../services/permission";
|
||||
import { queryOrNot } from "../utils/relation";
|
||||
import { notFoundError } from "../utils/error";
|
||||
|
||||
// User in company can see.
|
||||
const permissionCond = createPermCondition((_) => true);
|
||||
|
|
@ -153,7 +154,9 @@ export class RequestListController extends Controller {
|
|||
include: {
|
||||
service: true,
|
||||
work: true,
|
||||
product: true,
|
||||
product: {
|
||||
include: { document: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -163,12 +166,25 @@ export class RequestListController extends Controller {
|
|||
prisma.requestWork.count({ where }),
|
||||
]);
|
||||
|
||||
return { result, page, pageSize, total };
|
||||
return {
|
||||
result: result.map((v) => {
|
||||
return Object.assign(v, {
|
||||
productService: Object.assign(v.productService, {
|
||||
product: Object.assign(v.productService.product, {
|
||||
document: v.productService.product.document.map((doc) => doc.name),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}),
|
||||
page,
|
||||
pageSize,
|
||||
total,
|
||||
};
|
||||
}
|
||||
|
||||
@Get("{requestWorkId}")
|
||||
async getRequestWorkById(@Path() requestWorkId: string) {
|
||||
return await prisma.requestWork.findFirst({
|
||||
const record = await prisma.requestWork.findFirst({
|
||||
include: {
|
||||
request: {
|
||||
include: {
|
||||
|
|
@ -180,12 +196,26 @@ export class RequestListController extends Controller {
|
|||
include: {
|
||||
service: true,
|
||||
work: true,
|
||||
product: true,
|
||||
product: {
|
||||
include: {
|
||||
document: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
where: { id: requestWorkId },
|
||||
});
|
||||
|
||||
if (!record) throw notFoundError("Request Work");
|
||||
|
||||
return Object.assign(record, {
|
||||
productService: Object.assign(record.productService, {
|
||||
product: Object.assign(record.productService.product, {
|
||||
document: record.productService.product.document.map((doc) => doc.name),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@Put("{requestWorkId}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue