public async search()

in source/packages/services/assetlibrary/src/search/search.lite.service.ts [34:78]


    public async search(model: SearchRequestModel, offset?:string, count?:number): Promise<[(GroupItem|DeviceItem)[],string,number]> {
        logger.debug(`search.lite.service search: in: model: ${JSON.stringify(model)}, offset:${offset}, count:${count}`);

        // validation
        ow(model, ow.object.nonEmpty);
        const type = model.types===undefined || model.types.length===0? undefined: model.types.filter(t=> t===TypeCategory.Device || t===TypeCategory.Group);
        ow(type,'type', ow.object.nonEmpty);
        const someFiltersDefined:boolean = model.ancestorPath!==undefined || model.eq!==undefined ||
            model.neq!==undefined || model.lt!==undefined || model.lte!==undefined ||
            model.gt!==undefined || model.gte!==undefined || model.startsWith!==undefined ||
            model.endsWith!==undefined || model.contains!==undefined;
        ow(someFiltersDefined, ow.boolean.true);

        // default pagination
        if (count===undefined) {
            count=this.DEFAULT_SEARCH_COUNT;
        }
        if (offset===undefined) {
            offset='0';
        }

        const models: (GroupItem|DeviceItem)[] = [];
        const results = await this.searchDao.search(model, offset, count);

        if (results===undefined) {
            count=0;
            logger.debug(`search.lite.service search: exit: models: undefined, offset:${offset}, count:${count}`);
            return [undefined, offset, count];
        }

        for(const r of results) {
            if (r.types.indexOf(TypeCategory.Group)>=0) {
                models.push(this.groupsAssembler.toGroupItem(r));
            } else if (r.types.indexOf(TypeCategory.Device)>=0) {
                models.push(this.devicesAssembler.toDeviceItem(r));
            }
        }

        if (models.length<count) {
            count=models.length;
        }

        logger.debug(`search.lite.service search: exit: models: ${JSON.stringify(models)}`);
        return [models,offset,count];
    }