-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (40 loc) · 1.11 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
module.exports = (bookshelf) => {
bookshelf.Model = bookshelf.Model.extend({
format: function(attr) {
return this.constructor.format(attr);
},
parse: function(attr) {
return this.constructor.parse(attr);
},
spot: function(args) {
return this.where(this.format(args));
}
}, {
arrangement: {},
format: function(attr) {
return this.formatArrangement(attr);
},
parse: function(attr) {
return this.parseArrangement(attr);
},
formatArrangement: function(attr) {
for (let key in attr) {
if (this.arrangement[key] !== undefined && typeof this.arrangement[key].format == 'function') {
attr[key] = this.arrangement[key].format(attr[key]);
}
}
return attr;
},
parseArrangement: function(attr) {
for (let key in attr) {
if (this.arrangement[key] !== undefined && typeof this.arrangement[key].parse == 'function') {
attr[key] = this.arrangement[key].parse(attr[key]);
}
}
return attr;
},
spot: function(args) {
return this.where(this.format(args));
}
});
}