@@ -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' ;
@@ -90,12 +91,16 @@ function createProjectAndPhases(req, project, projectTemplate, productTemplates)
90
91
productTemplates . forEach ( ( pt ) => {
91
92
productTemplateMap [ pt . id ] = pt ;
92
93
} ) ;
93
- return Promise . all ( _ . map ( phases , ( phase , phaseIdx ) =>
94
+ return Promise . all ( _ . map ( phases , ( phase , phaseIdx ) => {
95
+ const duration = _ . get ( phase , 'duration' , 1 ) ;
96
+ const startDate = moment . utc ( ) ;
94
97
// Create phase
95
- models . ProjectPhase . create ( {
98
+ return models . ProjectPhase . create ( {
96
99
projectId : newProject . id ,
97
100
name : _ . get ( phase , 'name' , `Stage ${ phaseIdx } ` ) ,
98
- duration : _ . get ( phase , 'duration' , 0 ) ,
101
+ duration,
102
+ startDate : startDate . format ( ) ,
103
+ endDate : moment . utc ( startDate ) . add ( duration - 1 , 'days' ) . format ( ) ,
99
104
status : _ . get ( phase , 'status' , PROJECT_PHASE_STATUS . DRAFT ) ,
100
105
budget : _ . get ( phase , 'budget' , 0 ) ,
101
106
updatedBy : req . authUser . userId ,
@@ -121,8 +126,8 @@ function createProjectAndPhases(req, project, projectTemplate, productTemplates)
121
126
result . newPhases . push ( newPhaseJson ) ;
122
127
return Promise . resolve ( ) ;
123
128
} ) ;
124
- } ) ,
125
- ) ) ;
129
+ } ) ;
130
+ } ) ) ;
126
131
} ) . then ( ( ) => Promise . resolve ( result ) ) ;
127
132
}
128
133
0 commit comments