feat: include document relation

This commit is contained in:
Methapon Metanipat 2024-11-08 09:32:33 +07:00
parent 65d7b5a07f
commit dd2128609d

View file

@ -178,6 +178,7 @@ export class ProductController extends Controller {
const [result, total] = await prisma.$transaction([
prisma.product.findMany({
include: {
document: true,
createdBy: true,
updatedBy: true,
},
@ -190,7 +191,7 @@ export class ProductController extends Controller {
]);
return {
result,
result: result.map((v) => ({ ...v, document: v.document.map((doc) => doc.name) })),
page,
pageSize,
total,
@ -202,6 +203,7 @@ export class ProductController extends Controller {
async getProductById(@Path() productId: string) {
const record = await prisma.product.findFirst({
include: {
document: true,
createdBy: true,
updatedBy: true,
},
@ -210,7 +212,7 @@ export class ProductController extends Controller {
if (!record) throw notFoundError("Product");
return record;
return { ...record, document: record.document.map((doc) => doc.name) };
}
@Post()