-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathindex.js
31 lines (27 loc) · 809 Bytes
/
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
'use strict';
var _ = require('lodash');
var models = {};
var normalizedPath = require('path').join(__dirname, './');
var files = require('fs').readdirSync(normalizedPath);
var filesCount = files.length * 1;
var count = 0;
var associate = function(models){
_.forOwn(models, function(value, key){
if(value.associate){
value.associate(models);
}
});
};
files.forEach(function(file) {
count = count + 1;
var splitFileName = file.split('.');
if (splitFileName[0] !== 'index') {
models[splitFileName[0]] = require('./' + splitFileName[0]);
}
if (count === filesCount) {
associate(models);
}
});
module.exports = models;
// Todo: Automatically generate tests with the schema structure
// Add the option of elasticsearch for API search