@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.6 kB
JavaScript
import{copy as e}from"../../libs/i18n/copy.mjs";import t from"../../libs/repositories/users.mjs";import{invalidateAuthCache as n}from"../auth/helpers/auth-cache.mjs";import r from"./checks/check-user-access.mjs";import i from"../../libs/formatters/index.mjs";const a=async(a,o)=>{if(!o.ids||o.ids.length===0)return{error:void 0,data:void 0};if(o.ids.includes(o.currentUserId))return{error:{type:`basic`,message:e(`server:core.users.self.delete.denied`),status:400},data:void 0};let s=new t(a.db.client,a.config.db),c=await r(a,{ids:o.ids});if(c.error)return c;let l=await s.selectMultiple({select:[`id`,`is_deleted`],where:[{key:`id`,operator:`in`,value:o.ids}],validation:{enabled:!0}});if(l.error)return l;let u=new Set(l.data.map(e=>e.id));if(o.ids.filter(e=>!u.has(e)).length>0)return{error:{type:`basic`,message:e(`server:core.user.not.found.message`),errors:{ids:{message:e(`server:core.documents.ids.not.found.partial`,{data:{ids:l.data.map(e=>e.id).join(`, `)}})}},status:404},data:void 0};let d=await s.count({where:[{key:`is_deleted`,operator:`=`,value:a.config.db.getDefault(`boolean`,`false`)}]});if(d.error)return d;if(i.parseCount(d.data?.count)-l.data.filter(e=>e.is_deleted===a.config.db.getDefault(`boolean`,`false`)).length<1)return{error:{type:`basic`,message:e(`server:core.users.last.user.delete.denied`),status:400},data:void 0};let f=await s.deleteMultiple({where:[{key:`id`,operator:`in`,value:o.ids}],returning:[`id`],validation:{enabled:!0}});return f.error?f:(await n(a),{error:void 0,data:void 0})};export{a as default};
//# sourceMappingURL=delete-multiple-permanently.mjs.map