import{ensureArrayQueryFilter as e}from"../ensureArrayQueryFilter.mjs";import{getFiltersAndPaginationFromBody as t}from"./getFiltersAndPaginationFromBody.mjs";const n=(n,r)=>{let{filters:i,...a}=t(n),{roles:o,organization:s}=r?.locals||n.locals||{},c={},l={updatedAt:-1},{firstName:u,lastName:d,email:f,emailVerified:p,role:m,search:h,sortBy:g,sortOrder:_,ids:v,fetchAll:y}=i??{};if(v&&(c={...c,_id:{$in:e(v)}},!(o.includes(`admin`)&&y===`true`))){let t=e(v)?.filter(e=>s?.membersIds?.map(String).includes(e))??[];c={...c,_id:{$in:t}}}if(u&&(c={...c,firstName:new RegExp(u,`i`)}),d&&(c={...c,lastName:new RegExp(d,`i`)}),f&&(c={...c,email:new RegExp(f,`i`)}),p!==void 0){let e=p===`true`;c={...c,emailVerified:e}}if(m&&(c={...c,role:m}),h){let e=new RegExp(h,`i`);c={...c,$or:[{firstName:e},{lastName:e},{email:e},{name:e}]}}return g&&_&&(_===`asc`||_===`desc`)&&(l={[g]:_===`asc`?1:-1}),{filters:c,sortOptions:l,...a}};export{n as getUserFiltersAndPagination};
//# sourceMappingURL=getUserFiltersAndPagination.mjs.map