Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
snippet: onSet(value => (instance.locked ? instance.snippet : value))(string()),
url: onSet(value => (instance.locked ? instance.url : value))(
string({ validation: validation.create("required") })
),
content: onSet(value => (instance.locked ? instance.content : value))(
content({ context })
),
settings: onSet(value => (instance.locked ? instance.settings : value))(
fields({
instanceOf: PbPageSettings
})
),
version: number(),
parent: context.commodo.fields.id(),
published: flow(
onSet(value => {
// Deactivate previously published revision
if (value && value !== instance.published && instance.isExisting()) {
instance.locked = true;
instance.publishedOn = new Date();
instance.registerHookCallback("beforeSave", async () => {
// TODO: setOnce
// Deactivate previously published revision
const publishedRev: PbPage = (await PbPage.findOne({
query: { published: true, parent: instance.parent }
}): any);
if (publishedRev) {
publishedRev.published = false;
await publishedRev.save();
}
});