Skip to content

Issue #130 #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/routes/projects/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import validate from 'express-validation';
import _ from 'lodash';
import Joi from 'joi';
import config from 'config';
import moment from 'moment';

import models from '../../models';
import { PROJECT_MEMBER_ROLE, PROJECT_STATUS, PROJECT_PHASE_STATUS, USER_ROLE, EVENT, REGEX } from '../../constants';
Expand Down Expand Up @@ -90,12 +91,17 @@ function createProjectAndPhases(req, project, projectTemplate, productTemplates)
productTemplates.forEach((pt) => {
productTemplateMap[pt.id] = pt;
});
return Promise.all(_.map(phases, (phase, phaseIdx) =>
return Promise.all(_.map(phases, (phase, phaseIdx) => {
const duration = _.get(phase, 'duration', 1);
const startDate = moment.utc().hours(0).minutes(0).seconds(0)
.milliseconds(0);
// Create phase
models.ProjectPhase.create({
return models.ProjectPhase.create({
projectId: newProject.id,
name: _.get(phase, 'name', `Stage ${phaseIdx}`),
duration: _.get(phase, 'duration', 0),
duration,
startDate: startDate.format(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@architectt1 Can we make sure that any date field does not persist time of the day in database. We kept the field to be datetime for future, but don't want to add the time details for date fields. I mean, it should always represent 00:00:00.000 in database.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assertion in unit test would be great to validate this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vikasrohit done in de0d52e.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @architectt1

endDate: moment.utc(startDate).add(duration - 1, 'days').format(),
status: _.get(phase, 'status', PROJECT_PHASE_STATUS.DRAFT),
budget: _.get(phase, 'budget', 0),
updatedBy: req.authUser.userId,
Expand All @@ -121,8 +127,8 @@ function createProjectAndPhases(req, project, projectTemplate, productTemplates)
result.newPhases.push(newPhaseJson);
return Promise.resolve();
});
}),
));
});
}));
}).then(() => Promise.resolve(result));
}

Expand Down
12 changes: 12 additions & 0 deletions src/routes/projects/create.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-unused-expressions */
import _ from 'lodash';
import chai from 'chai';
import moment from 'moment';
import sinon from 'sinon';
import request from 'supertest';

Expand Down Expand Up @@ -85,6 +86,7 @@ describe('Project create', () => {
phases: {
phase1: {
name: 'phase 1',
duration: 5,
products: [
{
id: 21,
Expand Down Expand Up @@ -116,6 +118,7 @@ describe('Project create', () => {
1: {
name: 'Design Stage',
status: 'open',
duration: 10,
details: {
description: 'detailed description',
},
Expand All @@ -130,6 +133,7 @@ describe('Project create', () => {
2: {
name: 'Development Stage',
status: 'open',
duration: 20,
products: [
{
id: 23,
Expand Down Expand Up @@ -440,6 +444,14 @@ describe('Project create', () => {
const phases = _.sortBy(resJson.phases, p => p.name);
phases[0].name.should.be.eql('Design Stage');
phases[0].status.should.be.eql('open');
phases[0].startDate.should.be.a('string');
phases[0].duration.should.be.eql(10);
const startDate = moment.utc(phases[0].startDate);
startDate.hours().should.be.eql(0);
startDate.minutes().should.be.eql(0);
startDate.seconds().should.be.eql(0);
startDate.milliseconds().should.be.eql(0);
new Date(phases[0].endDate).should.be.eql(startDate.add(9, 'days').toDate());
expect(phases[0].details).to.be.empty;
phases[0].products.should.have.lengthOf(1);
phases[0].products[0].name.should.be.eql('product 1');
Expand Down