This repository has been archived by the owner on Mar 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
101 lines (76 loc) · 2.01 KB
/
index.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'use strict';
/**
* @name emis-asat
* @description TODO
*
* @author Benson Maruchu <[email protected]>
* @author lally elias <[email protected]>
* @licence MIT
* @since 0.1.0
* @version 0.1.0
* @example
*
* const { app } = require('emis-asat');
* app.start();
*
*/
/* dependencies */
const path = require('path');
const _ = require('lodash');
const app = require('@lykmapipo/express-common');
const mongoose = require('mongoose');
require('mongoose-schema-jsonschema')(mongoose);
/* declarations */
const pkg = require(path.join(__dirname, 'package.json'));
const fields = [
'name',
'description',
'version',
'license',
'homepage',
'repository',
'bugs',
'sandbox',
'contributors'
];
/* extract information from package.json */
const info = _.merge({}, _.pick(pkg, fields));
/* export package(module) info */
exports.info = info;
/* import models */
const Permission =
require(path.join(__dirname, 'lib', 'permission.model'));
const Role =
require(path.join(__dirname, 'lib', 'role.model'));
const Party =
require(path.join(__dirname, 'lib', 'party.model'));
/* export party model */
exports.Permission = Permission;
exports.Role = Role;
exports.Party = Party;
/* export schema definition */
exports.definitions = {
Permission: Permission.jsonSchema(),
Role: Role.jsonSchema(),
Party: Party.jsonSchema(),
};
/* import routers*/
const partyRouter = require(path.join(__dirname, 'lib', 'party.http.router'));
const roleRouter = require(path.join(__dirname, 'lib', 'role.http.router'));
const permissionRouter =
require(path.join(__dirname, 'lib', 'permission.http.router'));
/* export party router */
exports.partyRouter = partyRouter;
exports.roleRouter = roleRouter;
exports.permissionRouter = permissionRouter;
/* export app */
Object.defineProperty(exports, 'app', {
get() {
//TODO bind oauth middlewares authenticate, token, authorize
/* bind routers */
app.mount(partyRouter);
app.mount(roleRouter);
app.mount(permissionRouter);
return app;
}
});