Repository navigation
Expand file tree
/
Copy pathbaseModel.js
More file actions
58 lines (51 loc) · 1.71 KB
/
Copy pathbaseModel.js
File metadata and controls
58 lines (51 loc) · 1.71 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
56
57
58
/**
* baseModel
*
* @module :: Model
* @description :: This is a base model for all models to use. Purpose of this is to provide
* some common attributes (static / dynamic) for all models that application
* uses. Usage in actual models:
*
* var _ = require("lodash");
*
* module.exports = _.merge(_.cloneDeep(require("../services/baseModel")), {
* attributes: {
* ...
* }
* });
*
* @docs :: http://sailsjs.org/#!documentation/models
* https://groups.google.com/forum/#!topic/sailsjs/GTGoOGHAEvE
*/
"use strict";
module.exports = {
schema: true,
attributes: {
createdUserId: {
type: "integer",
required: true
},
updatedUserId: {
type: "integer",
required: true
},
// Dynamic model data attributes
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;
}
return output;
},
createdAtObject: function() {
return (this.createdAt && this.createdAt != "0000-00-00 00:00:00")
? DateService.convertDateObjectToUtc(this.createdAt) : null;
},
updatedAtObject: function() {
return (this.updatedAt && this.updatedAt != "0000-00-00 00:00:00")
? DateService.convertDateObjectToUtc(this.updatedAt) : null;
}
}
};