Skip to content

Commit 2bcc524

Browse files
author
vikasrohit
authored
Merge pull request #138 from topcoder-platform/issue/130
Issue #130
2 parents 884335a + de0d52e commit 2bcc524

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/routes/projects/create.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import validate from 'express-validation';
44
import _ from 'lodash';
55
import Joi from 'joi';
66
import config from 'config';
7+
import moment from 'moment';
78

89
import models from '../../models';
910
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)
9192
productTemplates.forEach((pt) => {
9293
productTemplateMap[pt.id] = pt;
9394
});
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);
9599
// Create phase
96-
models.ProjectPhase.create({
100+
return models.ProjectPhase.create({
97101
projectId: newProject.id,
98102
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(),
100106
status: _.get(phase, 'status', PROJECT_PHASE_STATUS.DRAFT),
101107
budget: _.get(phase, 'budget', 0),
102108
updatedBy: req.authUser.userId,
@@ -122,8 +128,8 @@ function createProjectAndPhases(req, project, projectTemplate, productTemplates)
122128
result.newPhases.push(newPhaseJson);
123129
return Promise.resolve();
124130
});
125-
}),
126-
));
131+
});
132+
}));
127133
}).then(() => Promise.resolve(result));
128134
}
129135

src/routes/projects/create.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-unused-expressions */
22
import _ from 'lodash';
33
import chai from 'chai';
4+
import moment from 'moment';
45
import sinon from 'sinon';
56
import request from 'supertest';
67

@@ -85,6 +86,7 @@ describe('Project create', () => {
8586
phases: {
8687
phase1: {
8788
name: 'phase 1',
89+
duration: 5,
8890
products: [
8991
{
9092
id: 21,
@@ -116,6 +118,7 @@ describe('Project create', () => {
116118
1: {
117119
name: 'Design Stage',
118120
status: 'open',
121+
duration: 10,
119122
details: {
120123
description: 'detailed description',
121124
},
@@ -130,6 +133,7 @@ describe('Project create', () => {
130133
2: {
131134
name: 'Development Stage',
132135
status: 'open',
136+
duration: 20,
133137
products: [
134138
{
135139
id: 23,
@@ -440,6 +444,14 @@ describe('Project create', () => {
440444
const phases = _.sortBy(resJson.phases, p => p.name);
441445
phases[0].name.should.be.eql('Design Stage');
442446
phases[0].status.should.be.eql('open');
447+
phases[0].startDate.should.be.a('string');
448+
phases[0].duration.should.be.eql(10);
449+
const startDate = moment.utc(phases[0].startDate);
450+
startDate.hours().should.be.eql(0);
451+
startDate.minutes().should.be.eql(0);
452+
startDate.seconds().should.be.eql(0);
453+
startDate.milliseconds().should.be.eql(0);
454+
new Date(phases[0].endDate).should.be.eql(startDate.add(9, 'days').toDate());
443455
expect(phases[0].details).to.be.empty;
444456
phases[0].products.should.have.lengthOf(1);
445457
phases[0].products[0].name.should.be.eql('product 1');

0 commit comments

Comments
 (0)