feat: filter status created and active treated as same
This commit is contained in:
parent
fa8e21166b
commit
af6d915106
6 changed files with 84 additions and 25 deletions
|
|
@ -41,12 +41,22 @@ export class ProductGroup extends Controller {
|
|||
}
|
||||
|
||||
@Get()
|
||||
async getProductGroup(@Query() query: string = "") {
|
||||
async getProductGroup(@Query() query: string = "", @Query() status?: Status) {
|
||||
const filterStatus = (val?: Status) => {
|
||||
if (!val) return {};
|
||||
|
||||
return val !== Status.CREATED && val !== Status.ACTIVE
|
||||
? { status: val }
|
||||
: { OR: [{ status: Status.CREATED }, { status: Status.ACTIVE }] };
|
||||
};
|
||||
|
||||
const where = {
|
||||
OR: [{ name: { contains: query } }, { detail: { contains: query } }],
|
||||
OR: [
|
||||
{ name: { contains: query }, ...filterStatus(status) },
|
||||
{ detail: { contains: query }, ...filterStatus(status) },
|
||||
],
|
||||
} satisfies Prisma.ProductGroupWhereInput;
|
||||
const result = prisma.productGroup.findMany({ orderBy: { createdAt: "asc" }, where });
|
||||
return result;
|
||||
return prisma.productGroup.findMany({ orderBy: { createdAt: "asc" }, where });
|
||||
}
|
||||
|
||||
@Get("{groupId}")
|
||||
|
|
|
|||
|
|
@ -55,12 +55,24 @@ function imageLocation(id: string) {
|
|||
export class ProductController extends Controller {
|
||||
@Get()
|
||||
async getProduct(
|
||||
@Query() status?: Status,
|
||||
@Query() query: string = "",
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
) {
|
||||
const filterStatus = (val?: Status) => {
|
||||
if (!val) return {};
|
||||
|
||||
return val !== Status.CREATED && val !== Status.ACTIVE
|
||||
? { status: val }
|
||||
: { OR: [{ status: Status.CREATED }, { status: Status.ACTIVE }] };
|
||||
};
|
||||
|
||||
const where = {
|
||||
OR: [{ name: { contains: query } }, { detail: { contains: query } }],
|
||||
OR: [
|
||||
{ name: { contains: query }, ...filterStatus(status) },
|
||||
{ detail: { contains: query }, ...filterStatus(status) },
|
||||
],
|
||||
} satisfies Prisma.ProductWhereInput;
|
||||
|
||||
const [result, total] = await prisma.$transaction([
|
||||
|
|
|
|||
|
|
@ -43,10 +43,24 @@ export class ProductType extends Controller {
|
|||
}
|
||||
|
||||
@Get()
|
||||
async getProductType(@Query() query: string = "", @Query() productGroupId?: string) {
|
||||
async getProductType(
|
||||
@Query() query: string = "",
|
||||
@Query() productGroupId?: string,
|
||||
@Query() status?: Status,
|
||||
) {
|
||||
const filterStatus = (val?: Status) => {
|
||||
if (!val) return {};
|
||||
|
||||
return val !== Status.CREATED && val !== Status.ACTIVE
|
||||
? { status: val }
|
||||
: { OR: [{ status: Status.CREATED }, { status: Status.ACTIVE }] };
|
||||
};
|
||||
const where = {
|
||||
AND: { productGroupId },
|
||||
OR: [{ name: { contains: query } }, { detail: { contains: query } }],
|
||||
OR: [
|
||||
{ name: { contains: query }, ...filterStatus(status) },
|
||||
{ detail: { contains: query }, ...filterStatus(status) },
|
||||
],
|
||||
} satisfies Prisma.ProductTypeWhereInput;
|
||||
const result = prisma.productType.findMany({ orderBy: { createdAt: "asc" }, where });
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue