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