feat: add user relation on query
This commit is contained in:
parent
2bd30b735d
commit
9f3b8cd290
14 changed files with 259 additions and 41 deletions
|
|
@ -72,6 +72,8 @@ export class ProductGroup extends Controller {
|
|||
type: true,
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
|
|
@ -139,6 +141,10 @@ export class ProductGroup extends Controller {
|
|||
});
|
||||
|
||||
return await tx.productGroup.create({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...body,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
|
|
@ -171,6 +177,10 @@ export class ProductGroup extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.productGroup.update({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updatedByUserId: req.user.sub },
|
||||
where: { id: groupId },
|
||||
});
|
||||
|
|
@ -194,6 +204,12 @@ export class ProductGroup extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "Product group is in used.", "productGroupInUsed");
|
||||
}
|
||||
|
||||
return await prisma.productGroup.delete({ where: { id: groupId } });
|
||||
return await prisma.productGroup.delete({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: groupId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,6 +89,10 @@ export class ProductController extends Controller {
|
|||
|
||||
const [result, total] = await prisma.$transaction([
|
||||
prisma.product.findMany({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
take: pageSize,
|
||||
|
|
@ -118,6 +122,10 @@ export class ProductController extends Controller {
|
|||
@Security("keycloak")
|
||||
async getProductById(@Path() productId: string) {
|
||||
const record = await prisma.product.findFirst({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: productId },
|
||||
});
|
||||
|
||||
|
|
@ -145,6 +153,10 @@ export class ProductController extends Controller {
|
|||
@Security("keycloak")
|
||||
async createProduct(@Request() req: RequestWithUser, @Body() body: ProductCreate) {
|
||||
const productType = await prisma.productType.findFirst({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: body.productTypeId },
|
||||
});
|
||||
|
||||
|
|
@ -169,6 +181,10 @@ export class ProductController extends Controller {
|
|||
update: { value: { increment: 1 } },
|
||||
});
|
||||
return await prisma.product.create({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...body,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
|
|
@ -185,6 +201,10 @@ export class ProductController extends Controller {
|
|||
|
||||
if (productType.status === "CREATED") {
|
||||
await prisma.productType.update({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: body.productTypeId },
|
||||
data: { status: Status.ACTIVE },
|
||||
});
|
||||
|
|
@ -230,6 +250,10 @@ export class ProductController extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.product.update({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updatedByUserId: req.user.sub },
|
||||
where: { id: productId },
|
||||
});
|
||||
|
|
@ -268,6 +292,12 @@ export class ProductController extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "Product is in used.", "productInUsed");
|
||||
}
|
||||
|
||||
return await prisma.product.delete({ where: { id: productId } });
|
||||
return await prisma.product.delete({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: productId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,8 @@ export class ProductType extends Controller {
|
|||
_count: {
|
||||
select: { product: true },
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
|
|
@ -128,6 +130,10 @@ export class ProductType extends Controller {
|
|||
});
|
||||
|
||||
return await tx.productType.create({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...body,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
|
|
@ -178,7 +184,15 @@ export class ProductType extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.productType.update({
|
||||
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updatedByUserId: req.user.sub },
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...body,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
updatedByUserId: req.user.sub,
|
||||
},
|
||||
where: { id: typeId },
|
||||
});
|
||||
|
||||
|
|
@ -208,6 +222,12 @@ export class ProductType extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "Product type is in used.", "productTypeInUsed");
|
||||
}
|
||||
|
||||
return await prisma.productType.delete({ where: { id: typeId } });
|
||||
return await prisma.productType.delete({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: typeId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue