typeorm#Like TypeScript Examples

The following examples show how to use typeorm#Like. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: globalMethods.ts    From liferay-grow with MIT License 6 votes vote down vote up
applyFilters = (where: any = {}): any => {
  const data: any = {};

  for (const key in where) {
    const value = where[key];

    data[key] =
      typeof value === 'string' && value.includes('%') ? Like(value) : value;
  }

  return data;
}
Example #2
Source File: SettingService.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
// setting list
    public list(limit: number, select: any = [], relation: any = [], whereConditions: any = []): Promise<any> {
        const condition: any = {};

        if (select && select.length > 0) {
            condition.select = select;
        }

        if (relation && relation.length > 0) {
            condition.relations = relation;
        }

        condition.where = {};

        if (whereConditions && whereConditions.length > 0) {
            whereConditions.forEach((item: any) => {
                const operator: string = item.op;
                if (operator === 'where' && item.value !== '') {
                    condition.where[item.name] = item.value;
                } else if (operator === 'like' && item.value !== '') {
                    condition.where[item.name] = Like('%' + item.value + '%');
                }
            });
        }

        if (limit && limit > 0) {
            condition.take = limit;

        }
        console.log(condition);
        return this.settingsRepository.find(condition);
    }
Example #3
Source File: UserGroupService.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
// Role list
    public list(limit: any, offset: any, select: any= [], whereConditions: any = [], count: number | boolean): Promise<any> {
        const condition: any = {};

        if (select && select.length > 0) {
            condition.select = select;
        }
        condition.where = {};

        if (whereConditions && whereConditions.length > 0) {
            whereConditions.forEach((table: any) => {
                const operator: string = table.op;
                if (operator === 'where' && table.value !== undefined) {
                    condition.where[table.name] = table.value;
                } else if (operator === 'like' && table.value !== undefined) {
                    condition.where[table.name] = Like('%' + table.value + '%');
                }
            });
        }

        if (limit && limit > 0) {
            condition.take = limit;
            condition.skip = offset;
        }

        console.log(condition);

        if (count) {
            return this.userGroupRepository.count(condition);
        }
        return this.userGroupRepository.find(condition);
    }
Example #4
Source File: applications.ts    From Designer-Server with GNU General Public License v3.0 5 votes vote down vote up
async listApplication(call: grpc.ServerUnaryCall<ListApplicationRequest>, callback: grpc.sendUnaryData<GApplicationList>): Promise<void> {
    try {
      var page = call.request.getPage();
      var perPage = call.request.getPerPage();
      var nameSpace = call.request.getNameSpace();

      if(!page) page = 1;
      if(!perPage) perPage = 10;

      const findOption:FindManyOptions = {
        select: ["id", "nameSpace", "title", "description" ,"status" ,"userId" ,"createdAt" ,"updatedAt"],
        skip: perPage*(page - 1),
        take: perPage,
        order: {
          id: 'ASC'
        },
        where: {}
      }

      if (nameSpace) {
        findOption.where["nameSpace"] = Like(`%${nameSpace}%`)
      }
      const applicationRepo = getRepository(Application);
      const findResult = await applicationRepo.findAndCount(findOption);
      
      
      const applicationList = new GApplicationList();
      applicationList.setTotalCount(findResult[1]);
      applicationList.setPage(page);
      applicationList.setPerPage(perPage);
      applicationList.setApplicationsList(findResult[0].map((app) => {
        const application = new GApplication();
        application.setId(app.id);
        application.setCreatedAt(app.createdAt.toDateString());
        application.setDescription(app.description);
        application.setNameSpace(app.nameSpace);
        application.setTitle(app.title);
        application.setUpdatedAt(app.updatedAt.toDateString());
        application.setUserId(app.userId);
        return application;
      }))
      callback(null, applicationList);
    } catch (err) {
      callback(err, null);
    }
  }
Example #5
Source File: ProductService.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
// product list
    public list(limit: number, offset: number, select: any = [], relation: any = [], whereConditions: any = [], search: any = [], price: number, count: number | boolean): Promise<any> {
        const condition: any = {};

        if (select && select.length > 0) {
            condition.select = select;
        }

        if (relation && relation.length > 0) {
            condition.relations = relation;
        }

        condition.where = {};

        if (whereConditions && whereConditions.length > 0) {
            whereConditions.forEach((item: any) => {
                const operator: string = item.op;
                if (operator === 'where' && item.value !== '') {
                    condition.where[item.name] = item.value;
                } else if (operator === 'like' && item.value !== '') {
                    condition.where[item.name] = Like('%' + item.value + '%');
                }
            });
        }

        if (search && search.length > 0) {
            search.forEach((item: any) => {
                const operator: string = item.op;
                if (operator === 'like' && item.value !== '') {
                    condition.where[item.name] = Like('%' + item.value + '%');
                }
            });
        }

        if (price && price === 1) {
            condition.order = {
                price: 'ASC',
                createdDate: 'DESC',
            };
        } else if (price && price === 2) {
            condition.order = {
                price: 'DESC',
                createdDate: 'DESC',
            };
        } else {
            condition.order = {
                createdDate: 'DESC',
            };
        }

        if (limit && limit > 0) {
            condition.take = limit;
            condition.skip = offset;
        }

        console.log(condition);
        if (count) {
            return this.productRepository.count(condition);
        }
        return this.productRepository.find(condition);
    }
Example #6
Source File: ProductToCategoryService.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
// product list
    public list(limit: number, offset: number, select: any = [], relation: any = [], whereConditions: any = [], price: number, count: number| boolean): Promise<any> {
        const condition: any = {};

        if (select && select.length > 0) {
            condition.select = select;
        }

        if (relation && relation.length > 0) {
            condition.relations = relation;
        }

        condition.where = {};

        if (whereConditions && whereConditions.length > 0) {
            whereConditions.forEach((item: any) => {
                const operator: string = item.op;
                if (operator === 'where' && item.value !== '') {
                    condition.where[item.name] = item.value;
                } else if (operator === 'like' && item.value !== '') {
                    condition.where[item.name] = Like('%' + item.value + '%');
                }
            });
        }

        if ( price && price === 1) {
            condition.order = {
                price : 'ASC',
            };
        }

        if ( price && price === 2) {
            condition.order = {
                price : 'DESC',
            };
        }

        if (limit && limit > 0) {
            condition.take = limit;
            condition.skip = offset;
        }

        console.log(condition);
        if (count) {
            return this.productToCategoryRepository.count(condition);
        }
        return this.productToCategoryRepository.find(condition);
    }
Example #7
Source File: UserService.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
// user list
    public list(limit: number = 0, offset: number = 0, select: any = [], relation: any = [], whereConditions: any = [], keyword: string, count: number | boolean): Promise<any> {
        console.log(keyword);
        const condition: any = {};

        if (select && select.length > 0) {
            condition.select = select;
        }

        if (relation && relation.length > 0) {
            condition.relations = relation;
        }

        condition.where = {};

        if (whereConditions && whereConditions.length > 0) {
            whereConditions.forEach((item: any) => {
                condition.where[item.name] = item.value;
            });
        }
        if (keyword) {
            condition.where = {
                firstName: Like('%' + keyword + '%'),
            };
        }

        condition.order = {
            createdDate: 'DESC',
        };

        if (limit && limit > 0) {
            condition.take = limit;
            condition.skip = offset;
        }

        if (count) {
            return this.userLoginRepository.count(condition);
        } else {
            return this.userLoginRepository.find(condition);
        }

    }