Last active
June 25, 2016 19:42
-
-
Save z81/005626c3e3b22d4af320bb781f3b7571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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