Skip to content

Instantly share code, notes, and snippets.

@z81
Last active June 25, 2016 19:42
Show Gist options
  • Save z81/005626c3e3b22d4af320bb781f3b7571 to your computer and use it in GitHub Desktop.
Save z81/005626c3e3b22d4af320bb781f3b7571 to your computer and use it in GitHub Desktop.
import { Schema, VirtualSchema, Types, config } from 'radiance';
Radiance({
schema: {
session: SESSION
},
acl: {
isAdmin: u => u.id === 1,
isSelf: (u, args) => u.id === args.id
}
})
const projectSchema = Schema('project', {
name: Types.string()
});
const messageSchema = Schema('message', {
text: Types.string(),
[config]: {
update: ['isAdmin', 'isSelf'],
delete: false
}
});
const userSchema = Schema('user', {
firs_name: Types.string(),
last_name: Types.string(10),
nickname: Types.string(),
password: Types.string().required().hidden(), // не будет в json
permission: Types.number(5).required(),
projects: [projectSchema], // many to many
messages: messageSchema,
[config]: {
beforeUpdate: ({ args, res }) => {
if (args.permission && !this.isAdmin) return false;
return args;
},
delete: ['isAdmin', 'isSelf']
}
});
const auth = VirtualSchema('auth', {
login: Types.string,
pass: Types.string,
[config]: {
resolve: ({ args, context, res })=> {
const user = userSchema.find(args);
if (user) {
res.session.user = user;
}
return user;
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment