-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
60 lines (54 loc) · 2.08 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
//dependencies
var path = require('path'),
libPath = path.join(__dirname, 'libs'),
modelFolder = path.join(__dirname,'models'),
findOne = require(path.join(libPath, 'findOne')),
findM = require(path.join(libPath, 'find')),
findOrCreate = require(path.join(libPath,'findOrCreate')),
update = require(path.join(libPath, 'update')),
create = require(path.join(libPath,'create')),
destory = require(path.join(libPath,'delete')),
ultis = require(path.join(libPath,'ultis')),
auditModel = require(path.join(modelFolder,'auditTrail'))
module.exports = function(sails) {
function patch() {
var config = {}
if(sails.config.hasOwnProperty('audittrail'))
config = sails.config.audittrail
if(sails.config.connections.hasOwnProperty(config.connection)) {
config.connection = sails.config.connections[config.connection]
}
auditModel(config).init(function(err,auditModel) {
config.model = auditModel
sails
.util
._(sails.models)
.forEach(function(model) {
//bind path validate
//on concrete models
//and left derived model
//build from associations
if (model.globalId && !ultis.isExcluded(model,config)) {
findOne(model,config);
findM(model,config);
update(model,config);
findOrCreate(model,config);
create(model,config)
destory(model,config)
//patch sails `create()` method
}
});
})
}
return {
//intercent all request and current grab request locale
initialize: function(done) {
sails.after('hook:orm:loaded', function() {
//bind custom errors logic
//and let sails to continue
patch();
done();
});
}
};
}