-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.js
61 lines (42 loc) · 1.19 KB
/
blog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"use strict";
module.exports = function( options ) {
var seneca = this
var name = "blog"
var postent = seneca.make$('post')
var commentent = seneca.make$('comment')
// TODO:
// field restrict
// field validate
seneca.add({role:'entity',cmd:'remove',name:'post'},function(args,done){
var seneca = this
commentent.list$({post:args.q.id},function(err,list){
if( err ) return done(err);
list.forEach(function(comment){
comment.remove$()
})
})
seneca.prior(args,done)
})
seneca.add({role:'entity',cmd:'save',name:'comment'},function(args,done){
var seneca = this
postent.load$(args.ent.post,function(err,post){
if( err ) return done(err);
args.ent.owner = post.owner
seneca.prior(args,done)
})
})
seneca.add({role:'user',cmd:'register'},function(args,done){
args.perm = {
own:{post:'*', comment:'*'}
}
this.prior(args,done)
})
seneca.add({init:name}, function( args, done ){
seneca.act('role:util, cmd:define_sys_entity',
{list:[ 'post', 'comment' ]})
seneca.act('role:user,cmd:register,name:U1,nick:u1,pass:u1')
})
return {
name:name
}
}