@@ -4,6 +4,7 @@ import validate from 'express-validation';
4
4
import _ from 'lodash' ;
5
5
import Joi from 'joi' ;
6
6
import config from 'config' ;
7
+ import moment from 'moment' ;
7
8
8
9
import models from '../../models' ;
9
10
import { PROJECT_MEMBER_ROLE , PROJECT_STATUS , PROJECT_PHASE_STATUS , USER_ROLE , EVENT , REGEX } from '../../constants' ;
@@ -91,12 +92,17 @@ function createProjectAndPhases(req, project, projectTemplate, productTemplates)
91
92
productTemplates . forEach ( ( pt ) => {
92
93
productTemplateMap [ pt . id ] = pt ;
93
94
} ) ;
94
- return Promise . all ( _ . map ( phases , ( phase , phaseIdx ) =>
95
+ return Promise . all ( _ . map ( phases , ( phase , phaseIdx ) => {
96
+ const duration = _ . get ( phase , 'duration' , 1 ) ;
97
+ const startDate = moment . utc ( ) . hours ( 0 ) . minutes ( 0 ) . seconds ( 0 )
98
+ . milliseconds ( 0 ) ;
95
99
// Create phase
96
- models . ProjectPhase . create ( {
100
+ return models . ProjectPhase . create ( {
97
101
projectId : newProject . id ,
98
102
name : _ . get ( phase , 'name' , `Stage ${ phaseIdx } ` ) ,
99
- duration : _ . get ( phase , 'duration' , 0 ) ,
103
+ duration,
104
+ startDate : startDate . format ( ) ,
105
+ endDate : moment . utc ( startDate ) . add ( duration - 1 , 'days' ) . format ( ) ,
100
106
status : _ . get ( phase , 'status' , PROJECT_PHASE_STATUS . DRAFT ) ,
101
107
budget : _ . get ( phase , 'budget' , 0 ) ,
102
108
updatedBy : req . authUser . userId ,
@@ -122,8 +128,8 @@ function createProjectAndPhases(req, project, projectTemplate, productTemplates)
122
128
result . newPhases . push ( newPhaseJson ) ;
123
129
return Promise . resolve ( ) ;
124
130
} ) ;
125
- } ) ,
126
- ) ) ;
131
+ } ) ;
132
+ } ) ) ;
127
133
} ) . then ( ( ) => Promise . resolve ( result ) ) ;
128
134
}
129
135
0 commit comments