diff --git a/src/store/dto/store-items.dto.ts b/src/store/dto/store-items.dto.ts index bc9cb2e..59eb0a2 100644 --- a/src/store/dto/store-items.dto.ts +++ b/src/store/dto/store-items.dto.ts @@ -75,6 +75,10 @@ export class ListStoreItemsDto { @IsInt() @Min(1) pageSize?: number; + + @IsOptional() + @IsString() + name?: string; } export class ListPublicStoreItemsDto { diff --git a/src/store/store-items.service.ts b/src/store/store-items.service.ts index 5a80e8e..19b9cb6 100644 --- a/src/store/store-items.service.ts +++ b/src/store/store-items.service.ts @@ -68,7 +68,27 @@ export class StoreItemsService { const page = query.page ?? 1; const pageSize = query.pageSize ?? 20; const skip = (page - 1) * pageSize; - const where = { businessId }; + const name = query.name?.trim(); + const where: Prisma.StoreItemVariantWhereInput = { + businessId, + ...(name + ? { + storeItem: { + product: { + OR: [ + { title: { contains: name, mode: 'insensitive' } }, + { + content: { + path: ['nameFa'], + string_contains: name, + }, + }, + ], + }, + }, + } + : {}), + }; const [items, total] = await Promise.all([ this.prisma.storeItemVariant.findMany({