forked from linnovate/meanio-circles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (51 loc) · 1.29 KB
/
app.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
62
63
'use strict'
/*
* Defining the Package
*/
var Module = require('meanio').Module
var mongoose = require('mongoose')
var Circles = new Module('circles')
/*
* All MEAN packages require registration
* Dependency injection is used to define required modules
*/
Circles.register(function (app, auth, database) {
Circles.controller = require('./server/controllers/circles')(Circles, app)
Circles.registerCircle = registerCircle
Circles.routes(app, auth, database)
Circles.angularDependencies(['mean.users'])
Circles.menus.add({
title: 'Circles',
link: 'manage circles',
roles: ['authenticated', 'admin'],
menu: 'main'
})
Circles.models = {}
return Circles
})
function registerCircle (name, parents) {
var Circle = require('mongoose').model('Circle')
var query = { name: name }
var set = {}
if (parents) {
set.$push = {
circles: parents
}
}
Circle.findOne(query, function (err, data) {
if (!err && !data) {
Circle.findOneAndUpdate(query, set, {
upsert: true
}, function (err) {
if (err) {
console.log(err)
}
})
}
})
}
/*
Y Override queries to check user permisisons
Y Add middleware for checking for specific circles by name
O Page to create and manage circles + sow circles heirarchy
*/