feat: paging group / type product
This commit is contained in:
parent
3211cbe8b7
commit
e3dac5529f
2 changed files with 27 additions and 10 deletions
|
|
@ -43,7 +43,12 @@ export class ProductGroup extends Controller {
|
|||
}
|
||||
|
||||
@Get()
|
||||
async getProductGroup(@Query() query: string = "", @Query() status?: Status) {
|
||||
async getProductGroup(
|
||||
@Query() query: string = "",
|
||||
@Query() status?: Status,
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
) {
|
||||
const filterStatus = (val?: Status) => {
|
||||
if (!val) return {};
|
||||
|
||||
|
|
@ -58,10 +63,16 @@ export class ProductGroup extends Controller {
|
|||
{ detail: { contains: query }, ...filterStatus(status) },
|
||||
],
|
||||
} satisfies Prisma.ProductGroupWhereInput;
|
||||
return prisma.productGroup.findMany({
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
});
|
||||
|
||||
const [result, total] = await prisma.$transaction([
|
||||
prisma.productGroup.findMany({
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
}),
|
||||
prisma.productGroup.count({ where }),
|
||||
]);
|
||||
|
||||
return { result, page, pageSize, total };
|
||||
}
|
||||
|
||||
@Get("{groupId}")
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ export class ProductType extends Controller {
|
|||
@Query() query: string = "",
|
||||
@Query() productGroupId?: string,
|
||||
@Query() status?: Status,
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
) {
|
||||
const filterStatus = (val?: Status) => {
|
||||
if (!val) return {};
|
||||
|
|
@ -64,11 +66,15 @@ export class ProductType extends Controller {
|
|||
{ detail: { contains: query }, ...filterStatus(status) },
|
||||
],
|
||||
} satisfies Prisma.ProductTypeWhereInput;
|
||||
const result = prisma.productType.findMany({
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
});
|
||||
return result;
|
||||
const [result, total] = await prisma.$transaction([
|
||||
prisma.productType.findMany({
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
}),
|
||||
prisma.productType.count({ where }),
|
||||
]);
|
||||
|
||||
return { result, page, pageSize, total };
|
||||
}
|
||||
|
||||
@Get("{typeId}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue