Repository navigation
Expand file tree
/
Copy pathProject.js
More file actions
100 lines (89 loc) · 2.49 KB
/
Copy pathProject.js
File metadata and controls
100 lines (89 loc) · 2.49 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Project
*
* @module :: Model
* @description :: This model represents project on taskboard.
* @docs :: http://sailsjs.org/#!documentation/models
*/
"use strict";
var _ = require("lodash");
module.exports = _.merge(_.cloneDeep(require("../services/baseModel")), {
attributes: {
// Relation to User model
managerId: {
type: "integer",
required: true
},
// Project title
title: {
type: "string",
required: true,
minLength: 4
},
// Description of the project
description: {
type: "text",
required: true,
defaultsTo: ""
},
// Project start date
dateStart: {
type: "date",
required: true
},
// Project end date
dateEnd: {
type: "date",
required: true
},
// Ignore weekends on this project, affects to burndown chart and phase duration calculations
ignoreWeekends: {
type: "boolean",
defaultsTo: false
},
// Dynamic data attributes
dateStartObject: function() {
return (this.dateStart && this.dateStart != "0000-00-00")
? DateService.convertDateObjectToUtc(this.dateStart) : null;
},
dateEndObject: function() {
return (this.dateEnd && this.dateEnd != "0000-00-00")
? DateService.convertDateObjectToUtc(this.dateEnd) : null;
}
},
// Life cycle callbacks
/**
* After create callback.
*
* @param {sails.model.project} values
* @param {Function} next
*/
afterCreate: function(values, next) {
HistoryService.write("Project", values);
next();
},
/**
* After update callback.
*
* @param {sails.model.project} values
* @param {Function} next
*/
afterUpdate: function(values, next) {
HistoryService.write("Project", values);
next();
},
/**
* Before destroy callback.
*
* @param {{}} terms
* @param {Function} next
*/
beforeDestroy: function(terms, next) {
DataService.getProject(terms, function(error, project) {
if (!error) {
HistoryService.remove("Project", project.id);
}
next(error);
});
}
});