feat: include document relation
This commit is contained in:
parent
65d7b5a07f
commit
dd2128609d
1 changed files with 4 additions and 2 deletions
|
|
@ -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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue