@@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
2
2
import { IProduct } from './interfaces/product' ;
3
3
import { Product } from './entities/product.entity' ;
4
4
import { InjectRepository } from '@nestjs/typeorm' ;
5
- import { In , Repository } from 'typeorm' ;
5
+ import { ILike , In , Repository } from 'typeorm' ;
6
6
import { ProductDetail } from './entities/product-details.entity' ;
7
7
import { SortByOption , filterByPrice } from 'src/utils/helpers' ;
8
8
import { IGetProductsResponse } from 'src/utils/types' ;
@@ -20,6 +20,7 @@ export class ProductService implements IProduct {
20
20
async getAll ( query ) : Promise < IGetProductsResponse > {
21
21
const perPage = Number ( query [ 'perPage' ] ) || 10 ;
22
22
const currentPage = Number ( query [ 'page' ] ) || 1 ;
23
+ const searchValue = query [ 'search' ] || '' ;
23
24
24
25
const [ products , totalProduct ] = await this . productRepository . findAndCount ( {
25
26
where : {
@@ -30,6 +31,7 @@ export class ProductService implements IProduct {
30
31
} ,
31
32
price : filterByPrice ( query [ 'price' ] ) ,
32
33
rate : query [ 'star' ] ? Number ( query [ 'star' ] ) : undefined ,
34
+ name : ILike ( `%${ searchValue } %` ) ,
33
35
} ,
34
36
relations : {
35
37
comment : true ,
0 commit comments