How to use the @webiny/commodo.onSet function in @webiny/commodo

To help you get started, we’ve selected a few @webiny/commodo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / webiny-js / packages / api-page-builder / src / plugins / models / pbPage.model.js View on Github external
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();
                            }
                        });