@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.44 kB
JavaScript
import{copy as e}from"../../libs/i18n/copy.mjs";import t from"../../libs/repositories/client-integration-scopes.mjs";import n from"../../libs/repositories/client-integrations.mjs";import r from"./checks/check-integration-access.mjs";import{getValidClientScopes as i}from"../../libs/permission/scopes.mjs";const a=async(a,o)=>{let s=o.scopes?[...new Set(o.scopes)]:void 0;if(s!==void 0){let t=new Set(i(a.config,{tenantKey:a.request.tenantKey})),n=s.filter(e=>!t.has(e));if(n.length>0)return{error:{type:`basic`,name:e(`server:core.client.integrations.scopes.error.name`),message:e(`server:core.client.integrations.scopes.invalid.message`,{data:{invalidScopes:n.join(`, `)}}),status:400},data:void 0}}let c=new n(a.db.client,a.config.db),l=new t(a.db.client,a.config.db),u=await r(a,{id:o.id});if(u.error)return u;let d=await c.updateSingle({data:{name:o.name,description:o.description,enabled:o.enabled,updated_at:new Date().toISOString()},where:[{key:`id`,operator:`=`,value:o.id}],returning:[`id`],validation:{enabled:!0}});if(d.error)return d;if(s!==void 0){let e=await l.deleteMultiple({where:[{key:`client_integration_id`,operator:`=`,value:o.id}],returning:[`id`],validation:{enabled:!0}});if(e.error)return e;if(s.length>0){let e=await l.createMultiple({data:s.map(e=>({client_integration_id:o.id,scope:e,core:!0}))});if(e.error)return e}}return{error:void 0,data:void 0}};export{a as default};
//# sourceMappingURL=update-single.mjs.map