Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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();
}
});
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 }
});
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());
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.`);
}
},
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()
})()
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());
};
export default ({ createBase, SecurityGroup }) =>
flow(
withName("SecurityGroups2Models"),
withFields(() => ({
model: ref({ instanceOf: [], refNameField: "modelName" }),
modelName: string(),
group: ref({
instanceOf: SecurityGroup
})
}))
)(createBase());
export default ({ createBase, SecurityRole }) =>
flow(
withName("SecurityRoles2Models"),
withFields(() => ({
model: ref({ instanceOf: [], refNameField: "modelClassId" }),
modelClassId: string(),
role: ref({
instanceOf: SecurityRole
})
}))
)(createBase());
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") }),
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());