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,user:s}=r?.locals||n.locals||{},c={},l={updatedAt:-1},{name:u,search:d,ids:f,membersIds:p,fetchAll:m,sortBy:h,sortOrder:g}=i??{};if(f&&(c={...c,_id:{$in:e(f)}}),o.includes(`admin`)&&m===`true`||(c={...c,membersIds:{$in:[s?.id]}}),u&&(c={...c,name:new RegExp(u,`i`)}),d){let e=new RegExp(d,`i`);c={...c,$or:[{name:e}]}}return p&&(c={...c,membersIds:{$in:e(p)}}),h&&g&&(g===`asc`||g===`desc`)&&(l={[h]:g===`asc`?1:-1}),{filters:c,sortOptions:l,...a}};export{n as getOrganizationFiltersAndPagination};
//# sourceMappingURL=getOrganizationFiltersAndPagination.mjs.map