@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.55 kB
JavaScript
import{copy as e}from"../../libs/i18n/copy.mjs";import t from"../../libs/repositories/documents.mjs";import{getTableNames as n}from"../../libs/collection/schema/runtime/runtime-schema-selectors.mjs";import r from"../collections/get-single-instance.mjs";import i from"../documents/checks/check-document-access.mjs";import a from"./promote-version.mjs";import o from"../../libs/formatters/index.mjs";const s=async(s,c)=>{let l=new t(s.db.client,s.config.db),u=r(s,{key:c.collectionKey});if(u.error)return u;if(u.data.getData.revisions===!1)return{error:{type:`basic`,name:e(`server:core.documents.revisions.not.enabled.error.name`),message:e(`server:core.documents.revisions.not.enabled.message`),status:400},data:void 0};let d=await n(s,c.collectionKey);if(d.error)return d;let f=await i(s,{collectionKey:c.collectionKey,id:c.documentId});if(f.error)return f;let p=await l.selectSingle({select:[`id`,`is_deleted`],where:[{key:`id`,operator:`=`,value:c.documentId}],validation:{enabled:!0,defaultError:{message:e(`server:core.documents.not.found.message`),status:404}}},{tableName:d.data.document});if(p.error)return p;if(o.formatBoolean(p.data.is_deleted))return{error:{type:`basic`,message:e(`server:core.documents.revisions.restore.deleted.document`),status:400},data:void 0};let m=await a(s,{documentId:c.documentId,collectionKey:c.collectionKey,fromVersionId:c.versionId,toVersionType:`latest`,userId:c.userId,skipRevisionCheck:!0});return m.error?m:{error:void 0,data:void 0}};export{s as default};
//# sourceMappingURL=restore-revision.mjs.map