How to use the webiny-validation.validation.create function in webiny-validation

To help you get started, we’ve selected a few webiny-validation 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 / webiny-api-security / src / models / SecurityUser.model.js View on Github external
return value;
                }

                value = value.toLowerCase().trim();
                instance.registerHookCallback("beforeSave", async () => {
                    const existingUser = await getModel("SecurityUser").findOne({
                        query: { email: value }
                    });
                    if (existingUser) {
                        throw Error("User with given e-mail already exists.");
                    }
                });
                // TODO .setOnce();

                return value;
            })(string({ validation: validation.create("required,email") }))
        })),
        withName("SecurityUser")
github webiny / webiny-js / packages / webiny-api-forms / src / models / Form.model.js View on Github external
withFields(instance => ({
            publishedOn: skipOnPopulate()(date()),
            name: string({ validation: validation.create("required") }),
            content: string(),
            version: number(),
            parent: string(),
            published: onSet(value => {
                // Deactivate previously published revision
                if (value && value !== instance.published && instance.isExisting()) {
                    instance.locked = true;
                    instance.publishedOn = new Date();
                    instance.registerHookCallback("beforeSave", async () => {
                        // Deactivate previously published revision
                        const publishedRev = (await getModel("Form").findOne({
                            query: { published: true, parent: instance.parent }
                        }): any);

                        if (publishedRev) {
                            publishedRev.published = false;
github webiny / webiny-js / packages / webiny-api-security / src / models / SecurityRole.model.js View on Github external
const existingRole = await getModel("SecurityRole").findOne({
                    query: { slug: this.slug }
                });
                if (existingRole) {
                    throw Error(`Role with slug "${this.slug}" already exists.`);
                }
            },
            async beforeDelete() {
                if (this.system) {
                    throw Error(`Cannot delete system role.`);
                }
            }
        }),
        withFields({
            name: string({ validation: validation.create("required") }),
            slug: setOnce()(string({ validation: validation.create("required") })),
            description: string(),
            scopes: string({ list: true }),
            system: boolean()
        }),
        withName("SecurityRole")
    )(Model);

webiny-validation

A simple data validation library, packed with frequently used validators.

MIT
Latest version published 5 years ago

Package Health Score

66 / 100
Full package analysis