forked from kanglei1130/drivesense-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbobject.js
40 lines (34 loc) · 982 Bytes
/
dbobject.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
var Class = require("./simple-inheritance.js")
var DBObject = Class.extend({
init:function DBObject(){},
fromObject:function(uobj) {
var all_keys = this.constructor.private.concat(this.constructor.user_facing);
for (var i = 0; i < all_keys.length; ++i) {
var key = all_keys[i];
if(uobj[key] !== undefined) {
this[key] = uobj[key];
}
}
},
fromObjectSafe: function(uobj) {
for (var i = 0; i < this.constructor.user_facing.length; ++i) {
var key = this.constructor.user_facing[i];
if(uobj[key] !== undefined) {
this[key] = uobj[key];
}
}
},
user_facing_vals:function() {
var output = {};
for (var i = 0; i < this.constructor.user_facing.length; ++i) {
var key = this.constructor.user_facing[i];
if(this[key] !== undefined) {
output[key] = this[key];
}
}
return output;
}
});
DBObject.user_facing = [];
DBObject.private = []
module.exports = DBObject;