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},{ids:u,userId:d,userIds:f,discussionId:p,search:m,isArchived:h,sortBy:g,sortOrder:_,fetchAll:v}=i??{};if(u&&(c={...c,_id:{$in:e(u)}}),p&&(c={...c,discussionId:p}),h!==void 0&&(c={...c,isArchived:h===`true`}),d&&(c={...c,userId:d}),f&&(c={...c,userId:{$in:e(f)}}),m){let e=new RegExp(m,`i`);c={...c,$or:[{discussionId:e},{title:e},{"messages.content":e}]}}g&&_&&(_===`asc`||_===`desc`)&&(l={[g]:_===`asc`?1:-1});let y=o.includes(`admin`);return(!y&&s?.id||y&&v!==`true`&&s?.id)&&(c={...c,userId:s.id}),{filters:c,sortOptions:l,...a}};export{n as getDiscussionFiltersAndPagination};
//# sourceMappingURL=getDiscussionFiltersAndPagination.mjs.map