How to use the @webiny/commodo.withProps 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 / form.model.js View on Github external
this.version = await this.getNextVersion();
            },
            async afterDelete() {
                // If the deleted form is the root form - delete its revisions
                if (this.id === this.parent) {
                    // Delete all revisions.
                    const revisions = await Form.find({
                        query: { parent: this.parent }
                    });

                    return Promise.all(revisions.map(rev => rev.delete()));
                }
            }
        }),
        withProps({
            get overallStats() {
                return new Promise(async resolve => {
                    const plugin = context.plugins.byName("forms-resolver-overall-stats");

                    if (!plugin) {
                        throw Error(
                            `Resolver plugin "forms-resolver-overall-stats" is not configured!`
                        );
                    }

                    const stats = await plugin.resolve({ form: this, context });

                    if (!stats) {
                        return resolve({
                            submissions: 0,
                            views: 0,
github webiny / webiny-js / packages / api-security / src / plugins / models / securityUser.model.js View on Github external
),
            firstName: string(),
            lastName: string(),
            roles: ref({
                list: true,
                instanceOf: [SecurityRole, "model"],
                using: [SecurityRoles2Models, "role"]
            }),
            groups: ref({
                list: true,
                instanceOf: [SecurityGroup, "model"],
                using: [SecurityGroups2Models, "group"]
            }),
            avatar: context.commodo.fields.id()
        })),
        withProps(instance => ({
            __access: null,
            get fullName() {
                return `${instance.firstName} ${instance.lastName}`.trim();
            },
            get gravatar() {
                return "https://www.gravatar.com/avatar/" + md5(instance.email);
            },
            get access() {
                if (this.__access) {
                    return this.__access;
                }

                return new Promise(async resolve => {
                    const access = {
                        scopes: [],
                        roles: [],
github webiny / webiny-js / packages / api-forms / src / plugins / models / formSubmission.model.js View on Github external
instanceOf: withFields({
                    type: string({
                        validation: validation.create("required,in:error:warning:info:success"),
                        message: string(),
                        data: object(),
                        createdOn: date({ value: new Date() })
                    })
                })()
            })
        })),
        withHooks({
            beforeCreate() {
                this.meta.submittedOn = new Date();
            }
        }),
        withProps({
            addLog(log) {
                if (!Array.isArray(this.logs)) {
                    this.logs = [];
                }

                this.logs = [...this.logs, log];
            }
        })
    )(createBase());
};
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();
            },
github webiny / webiny-js / packages / api-page-builder / src / plugins / models / pbSettings.model.js View on Github external
const step = () =>
    fields({
        value: {},
        instanceOf: flow(
            withFields({
                started: boolean({ value: false }),
                startedOn: date(),
                completed: boolean({ value: false }),
                completedOn: date()
            }),
            withProps({
                markAsStarted() {
                    this.started = true;
                    this.startedOn = new Date();
                },
                markAsCompleted() {
                    this.completed = true;
                    this.completedOn = new Date();
                }
            })
        )()
    });
github webiny / webiny-js / packages / api-forms / src / plugins / models / Form / createSettingsModel.js View on Github external
instanceOf: withFields({
                renderer: string({ value: "default" })
            })()
        }),
        submitButtonLabel: i18nString({ context }),
        successMessage: i18nObject({ context }),
        termsOfServiceMessage: fields({
            instanceOf: withFields({
                message: i18nObject({ context }),
                errorMessage: i18nString({ context }),
                enabled: boolean()
            })()
        }),
        reCaptcha: fields({
            instanceOf: flow(
                withProps({
                    settings: {
                        get enabled() {
                            return new Promise(async resolve => {
                                const settings = await FormSettings.load();
                                resolve(Boolean(get(settings, "data.reCaptcha.enabled")));
                            });
                        },
                        get siteKey() {
                            return new Promise(async resolve => {
                                const settings = await FormSettings.load();
                                resolve(get(settings, "data.reCaptcha.siteKey"));
                            });
                        },
                        get secretKey() {
                            return new Promise(async resolve => {
                                const settings = await FormSettings.load();
github webiny / webiny-js / packages / api-page-builder / src / plugins / models / pbPage.model.js View on Github external
const publishedRev: PbPage = (await PbPage.findOne({
                                query: { published: true, parent: instance.parent }
                            }): any);

                            if (publishedRev) {
                                publishedRev.published = false;
                                await publishedRev.save();
                            }
                        });
                    }
                    return value;
                })
            )(boolean({ value: false })),
            locked: skipOnPopulate()(boolean({ value: false }))
        })),
        withProps({
            async getNextVersion() {
                const revision = await PbPage.findOne({
                    query: { parent: this.parent, deleted: { $in: [true, false] } },
                    sort: { version: -1 }
                });

                if (!revision) {
                    return 1;
                }

                return revision.version + 1;
            },
            get isHomePage() {
                return new Promise(async resolve => {
                    const settings = await PbSettings.load();
                    resolve(settings.data.pages.home === this.parent);
github webiny / webiny-js / packages / api-files / src / plugins / models / file.model.js View on Github external
export default ({ createBase, context }) => {
    const File = flow(
        withName("File"),
        withProps({
            get src() {
                const settings = context.files.getSettings();
                return settings.data.srcPrefix + this.key;
            }
        }),
        withFields({
            key: setOnce()(string({ validation: validation.create("required,maxLength:200") })),
            size: number(),
            type: string({ validation: validation.create("maxLength:50") }),
            name: string({ validation: validation.create("maxLength:100") }),
            meta: object(),
            tags: onSet(value => {
                if (!Array.isArray(value)) {
                    return null;
                }