Repository navigation
Expand file tree
/
Copy pathModel.js
More file actions
55 lines (48 loc) · 1.65 KB
/
Copy pathModel.js
File metadata and controls
55 lines (48 loc) · 1.65 KB
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
'use strict';
/**
* api/base/model.js
*
* Base model for all sails.js models. This just contains some common code that every model uses
*/
module.exports = {
schema: true,
migrate: 'alter',
attributes: {
// Relation to User object via created user id
createdUser: {
model: 'User',
columnName: 'createdUserId',
required: true
},
// Relation to User object via updated user id
updatedUser: {
model: 'User',
columnName: 'updatedUserId',
required: true
},
// Dynamic model data attributes
// Object title normalization
objectTitle: function() {
var output = null;
if (this.title) {
output = this.title;
} else if (this.lastName) { // Small hack for User model
output = this.lastName + ' ' + this.firstName;
} else if (this.filename) { // And another hack for File model
output = this.filename;
}
// todo comment model?
return output;
},
// Created timestamp as moment object
createdAtObject: function() {
return (this.createdAt && this.createdAt != '0000-00-00 00:00:00')
? sails.services['date'].convertDateObjectToUtc(this.createdAt) : null;
},
// Updated timestamp as moment object
updatedAtObject: function() {
return (this.updatedAt && this.updatedAt != '0000-00-00 00:00:00')
? sails.services['date'].convertDateObjectToUtc(this.updatedAt) : null;
}
}
};