UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.13 kB
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-not-last-user.mjs";import i from"./checks/check-user-access.mjs";import a from"../../libs/formatters/index.mjs";const o=async(o,s)=>{let c=new t(o.db.client,o.config.db);if(s.currentUserId===s.userId)return{error:{type:`basic`,message:e(`server:core.users.self.delete.denied`),status:400},data:void 0};let l=await i(o,{id:s.userId});if(l.error)return l;let u=await c.selectSingle({select:[`id`,`is_deleted`],where:[{key:`id`,operator:`=`,value:s.userId}],validation:{enabled:!0,defaultError:{message:e(`server:core.user.not.found.message`),status:404}}});if(u.error)return u;if(!a.formatBoolean(u.data.is_deleted)){let e=await r(o);if(e.error)return e}let d=await c.deleteSingle({where:[{key:`id`,operator:`=`,value:s.userId}],returning:[`id`],validation:{enabled:!0,defaultError:{status:500}}});return d.error?d:(await n(o),{error:void 0,data:void 0})};export{o as default}; //# sourceMappingURL=delete-single-permanently.mjs.map