How to use the @webiny/commodo.withName 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-i18n / src / plugins / models / i18nLocale.model.js View on Github external
export default ({ createBase }) => {
    const I18NLocale = flow(
        withName("I18NLocale"),
        withFields(instance => ({
            default: onSet(value => {
                if (value !== instance.code && value === true) {
                    instance.registerHookCallback("afterSave", async () => {
                        console.log("TODO: setOnce");

                        const defaultLocales = await I18NLocale.find({
                            query: { default: true, id: { $ne: instance.id } }
                        });

                        for (let i = 0; i < defaultLocales.length; i++) {
                            let defaultLocale = defaultLocales[i];
                            defaultLocale.default = false;
                            await defaultLocale.save();
                        }
                    });
github webiny / webiny-js / packages / api-security / src / plugins / models / securityGroup.model.js View on Github external
export default ({ createBase, SecurityRole, SecurityRoles2Models }) => {
    const SecurityGroup = flow(
        withName("SecurityGroup"),
        withFields(() => ({
            description: string(),
            name: string(),
            slug: string(),
            system: boolean(),
            roles: ref({
                list: true,
                instanceOf: [SecurityRole, "model"],
                using: [SecurityRoles2Models, "role"]
            })
        })),
        withHooks({
            async beforeCreate() {
                const existingGroup = await SecurityGroup.findOne({
                    query: { slug: this.slug }
                });
github webiny / webiny-js / packages / api-page-builder / src / plugins / models / pbMenu.model.js View on Github external
export default ({ createBase }) => {
    const PbMenu = flow(
        withName("PbMenu"),
        withFields({
            title: string({ validation: validation.create("required") }),
            slug: setOnce()(string({ validation: validation.create("required") })),
            description: string(),
            items: object()
        }),
        withHooks({
            async beforeCreate() {
                const existingMenu = await PbMenu.findOne({ query: { slug: this.slug } });
                if (existingMenu) {
                    throw Error(`Menu with slug "${this.slug}" already exists.`);
                }
            }
        })
    )(createBase());
github webiny / webiny-js / packages / api-security / src / plugins / models / securityRole.model.js View on Github external
export default ({ createBase }) => {
    const SecurityRole = flow(
        withName("SecurityRole"),
        withFields({
            name: string(),
            slug: string(),
            description: string(),
            system: boolean(),
            scopes: string({ list: true })
        }),
        withHooks({
            async beforeCreate() {
                const existingRole = await SecurityRole.findOne({
                    query: { slug: this.slug }
                });
                if (existingRole) {
                    throw Error(`Role with slug "${this.slug}" already exists.`);
                }
            },
github webiny / webiny-js / packages / api-page-builder / src / plugins / models / pbSettings.model.js View on Github external
get completed() {
                for (let number = 1; number <= 5; number++) {
                    if (!this.getStep(number).completed) {
                        return false;
                    }
                }

                return true;
            }
        })
    )();

    const { id } = context.commodo.fields;

    return flow(
        withName("Settings"),
        withStaticProps({
            async load() {
                return await this.findOne({ query: { key: SETTINGS_KEY } });
            }
        }),
        withFields({
            key: setOnce()(string({ value: SETTINGS_KEY })),
            data: fields({
                value: {},
                instanceOf: withFields({
                    pages: fields({
                        instanceOf: withFields({
                            home: id(),
                            notFound: id(),
                            error: id()
                        })()
github webiny / webiny-js / packages / api-google-tag-manager / src / googleTagManagerSettings.model.js View on Github external
export default ({ createBase }) => {
    return flow(
        withName("Settings"),
        withStaticProps({
            async load() {
                return await this.findOne({ query: { key: SETTINGS_KEY } });
            }
        }),
        withFields({
            key: setOnce()(string({ value: SETTINGS_KEY })),
            data: fields({
                instanceOf: withFields({
                    enabled: boolean(),
                    code: string()
                })()
            })
        })
    )(createBase());
};
github webiny / webiny-js / packages / api-security / src / plugins / models / securityGroups2Models.model.js View on Github external
export default ({ createBase, SecurityGroup }) =>
    flow(
        withName("SecurityGroups2Models"),
        withFields(() => ({
            model: ref({ instanceOf: [], refNameField: "modelName" }),
            modelName: string(),
            group: ref({
                instanceOf: SecurityGroup
            })
        }))
    )(createBase());
github webiny / webiny-js / packages / api-security / src / plugins / models / securityRoles2Models.model.js View on Github external
export default ({ createBase, SecurityRole }) =>
    flow(
        withName("SecurityRoles2Models"),
        withFields(() => ({
            model: ref({ instanceOf: [], refNameField: "modelClassId" }),
            modelClassId: string(),
            role: ref({
                instanceOf: SecurityRole
            })
        }))
    )(createBase());
github webiny / webiny-js / packages / api-forms / src / plugins / models / formSubmission.model.js View on Github external
export default ({ createBase, Form }) => {
    return flow(
        withName("FormSubmission"),
        withFields(instance => ({
            form: fields({
                instanceOf: withFields({
                    parent: ref({
                        parent: instance,
                        instanceOf: Form,
                        validation: validation.create("required")
                    }),
                    revision: ref({
                        parent: instance,
                        instanceOf: Form,
                        validation: validation.create("required")
                    })
                })()
            }),
            data: object({ validation: validation.create("required") }),
github webiny / webiny-js / packages / api-page-builder / src / plugins / models / pbCategory.model.js View on Github external
export default ({ createBase }) =>
    flow(
        withName("PbCategory"),
        withFields({
            name: string({ validation: validation.create("required") }),
            slug: string({ validation: validation.create("required") }),
            url: string({ validation: validation.create("required") }),
            layout: string()
        })
    )(createBase());