public async getCompanies(pageIndex: number, isCreatingLicense: boolean, isSegnalator: boolean = false): Promise<any> {
const PAGE_SIZE = 20;
const from = pageIndex * PAGE_SIZE;
const to = (pageIndex + 1) * PAGE_SIZE - 1;
const request = this.service.supabase.from('companies').select('id, name', { count: 'exact' }).range(from, to);
const searchTerm = this.#search()?.toLowerCase() ?? '';
if (searchTerm) {
request.or(`id.ilike.%${searchTerm}%, name.ilike.%${searchTerm}%`);
}
if (isCreatingLicense === true) {
const currentCompany = this.service.getCompany();
request.or(`type.eq.CUSTOMER,id.eq.${currentCompany}`);
}
if (isSegnalator) {
request.neq('type', 'CUSTOMER');
}
request.order('name');
return await request.overrideTypes<Company[]>();
}
public async getCompanies(pageIndex: number, isCreatingLicense: boolean, isSegnalator: boolean = false): Promise<any> {
const PAGE_SIZE = 20;
const from = pageIndex * PAGE_SIZE;
const to = (pageIndex + 1) * PAGE_SIZE - 1;
const request = this.service.supabase.from('companies').select('id, name', { count: 'exact' }).range(from, to);
const searchTerm = this.#search()?.toLowerCase() ?? '';
if (searchTerm) {
request.or(`id.ilike.%${searchTerm}%, name.ilike.%${searchTerm}%`);
}
if (isCreatingLicense === true) {
const currentCompany = this.service.getCompany();
request.or(`type.eq.CUSTOMER,id.eq.${currentCompany}`);
}
if (isSegnalator) {
request.neq('type', 'CUSTOMER');
}
request.order('name');
return await request.overrideTypes<Company[]>();
}