Перейти к основному контенту

Сложный фильтр

const leads = await Global.ns._clients.app._leads.search()
        .where((f, g) => {
            let opperands: Filter[] = [];
            opperands.push(f.__deletedAt.eq(null));
            opperands.push(f.__createdAt.gte(Context.data.start_date!));
            opperands.push(f.__createdAt.lte(Context.data.end_date!));
            if (Context.data.status?.length) {
                let filterStatus: Filter[] = [];
                for (const adress of Context.data.adresses) {
                    filterStatus.push(f._address.eq(adress))
                }
                opperands.push(g.or(...filterStatus))
            }
            if (Context.data.companyes?.length) {
                let filterChannel: Filter[] = [];
                for (const company of Context.data.companies) {
                    filterChannel.push(f._companies.link(company))
                }
                opperands.push(g.or(...filterChannel))
            }
            return g.and(...opperands)
        })
        .size(10000)
        .all()