How to use the @webiny/commodo.withFields 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-forms / src / plugins / models.js View on Github external
const createBase = ({ maxPerPage = 100 } = {}) =>
            flow(
                withFields({
                    id: context.commodo.fields.id()
                }),
                withStorage({ driver, maxPerPage }),
                withUser(context),
                withSoftDelete(),
                withCrudLogs()
            )();
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-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 }
                });
                if (existingGroup) {
github webiny / webiny-js / packages / api-files / src / plugins / models.js View on Github external
const createBase = () =>
            flow(
                withFields({
                    id: context.commodo.fields.id()
                }),
                withStorage({ driver }),
                withUser(context),
                withSoftDelete(),
                withCrudLogs()
            )();
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") }),
            meta: fields({
github webiny / webiny-js / packages / api-cookie-policy / src / cookiePolicySettings.model.js View on Github external
export default ({ createBase }) => {
    const ColorsModel = withFields({
        background: string(),
        text: string()
    })();

    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(),
                    position: string({
                        value: "bottom",
                        validation: validation.create("in:bottom:top:bottom-left:bottom-right")
                    }),
                    palette: fields({
                        instanceOf: withFields({
                            popup: fields({ instanceOf: ColorsModel }),
                            button: fields({ instanceOf: ColorsModel })
                        })()
                    }),
                    content: fields({
                        instanceOf: withFields({
github webiny / webiny-js / packages / api-page-builder / src / plugins / models.js View on Github external
const createBase = ({ maxPerPage = 100 } = {}) =>
            flow(
                withFields({
                    id: context.commodo.fields.id()
                }),
                withStorage({ driver, maxPerPage }),
                withUser(context),
                withSoftDelete(),
                withCrudLogs()
            )();
github webiny / webiny-js / packages / api-cms / src / plugins / models.js View on Github external
const createBase = () =>
            flow(
                withFields({
                    id: context.commodo.fields.id()
                }),
                withStorage({ driver }),
                withUser(context),
                withSoftDelete(),
                withCrudLogs()
            )();
github webiny / webiny-js / packages / api-security / src / plugins / models.js View on Github external
const createBase = () =>
            flow(
                withFields({
                    id: context.commodo.fields.id()
                }),
                withStorage({ driver }),
                withUser(context),
                withSoftDelete(),
                withCrudLogs()
            )();
github webiny / webiny-js / packages / api-security / src / withUser.js View on Github external
export default context => baseFn => {
    return flow(
        withProps({
            getUser() {
                return context.user;
            },
            getUserId() {
                return context.user ? context.user.id : null;
            }
        }),
        withFields({
            createdBy: skipOnPopulate()(id()),
            updatedBy: skipOnPopulate()(id()),
            deletedBy: skipOnPopulate()(id())
        }),
        withHooks({
            beforeCreate() {
                this.createdBy = this.getUserId();
            },
            beforeUpdate() {
                this.updatedBy = this.getUserId();
            },
            beforeDelete() {
                this.deletedBy = this.getUserId();
            }
        })
    )(baseFn);