-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (60 loc) · 2.17 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
const Adminmate = ({ projectId, secretKey, authKey, masterPassword, models, charts, authorizedIps, devMode = false, testMode = false }) => {
const _conf = {};
_conf.projectId = projectId;
_conf.secretKey = secretKey;
_conf.authKey = authKey;
_conf.masterPassword = masterPassword;
_conf.models = models || [];
_conf.charts = charts || [];
_conf.authorizedIps = authorizedIps || null;
_conf.devMode = devMode;
_conf.testMode = testMode;
const amCore = require(_conf.devMode ? '../adminmate-express-core' : 'adminmate-express-core');
// Helpers
const fnHelper = require('./src/helpers/functions')(_conf);
// CRUD
const getAll = require('./src/controllers/model-getall')(_conf);
const getIn = require('./src/controllers/model-getin')(_conf);
const getOne = require('./src/controllers/model-getone')(_conf);
const getRefs = require('./src/controllers/model-getrefs')(_conf);
const postOne = require('./src/controllers/model-postone')(_conf);
const putOne = require('./src/controllers/model-putone')(_conf);
const deleteSome = require('./src/controllers/model-deletesome')(_conf);
const getAutocomplete = require('./src/controllers/model-autocomplete')(_conf);
const customQuery = require('./src/controllers/model-query')(_conf);
const api = {
// App config
getAppConfig: fnHelper.getAppConfig,
getAvailableFeatures: () => {
return {
charts: ['single_value', 'pie', 'bar', 'line', 'objective', 'ranking', 'map_point']
};
},
// General
getModelProperties: fnHelper.getModelProperties,
getModelRealname: fnHelper.getModelRealname,
getModelRelationships: fnHelper.getModelAssociations,
getModelPrimaryKeys: fnHelper.getModelPrimaryKeys,
getModelWhereClause: fnHelper.getModelWhereClause,
// CRUD
modelGetAll: getAll,
modelGetIn: getIn,
modelGetOne: getOne,
modelGetRefs: getRefs,
modelPostOne: postOne,
modelPutOne: putOne,
modelDeleteSome: deleteSome,
modelGetAutocomplete: getAutocomplete,
modelCustomQuery: customQuery
};
if (testMode === true) {
return api;
}
return amCore.init({
config: _conf,
api
});
};
module.exports = {
init: Adminmate
};