Skip to content

Commit 9cb3bc3

Browse files
author
Vikas Agarwal
committed
startDate endDate validation fix for null case
optional direct project id and billing account id
1 parent 7e596d4 commit 9cb3bc3

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/routes/phaseProducts/create.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const addPhaseProductValidations = {
1515
param: Joi.object().keys({
1616
name: Joi.string().required(),
1717
type: Joi.string().required(),
18-
templateId: Joi.number().optional(),
18+
templateId: Joi.number().positive().optional(),
19+
directProjectId: Joi.number().positive().optional(),
20+
billingAccountId: Joi.number().positive().optional(),
1921
estimatedPrice: Joi.number().positive().optional(),
2022
actualPrice: Joi.number().positive().optional(),
2123
details: Joi.any().optional(),

src/routes/phases/update.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ module.exports = [
6262
if (updatedProps.startDate) {
6363
startDate = new Date(updatedProps.startDate);
6464
} else {
65-
startDate = new Date(existing.startDate);
65+
startDate = existing.startDate !== null ? new Date(existing.startDate) : null;
6666
}
6767

6868
if (updatedProps.endDate) {
6969
endDate = new Date(updatedProps.endDate);
7070
} else {
71-
endDate = new Date(existing.endDate);
71+
endDate = existing.endDate !== null ? new Date(existing.endDate) : null;
7272
}
7373

74-
if (startDate >= endDate) {
74+
if (startDate !== null && endDate !== null && startDate >= endDate) {
7575
const err = new Error('startDate must be before endDate.');
7676
err.status = 400;
7777
reject(err);

src/routes/projects/list.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ const PROJECT_ATTACHMENT_ATTRIBUTES = _.without(
2929
_.keys(models.ProjectAttachment.rawAttributes),
3030
'deletedAt',
3131
);
32+
const PROJECT_PHASE_ATTRIBUTES = _.without(
33+
_.keys(models.ProjectPhase.rawAttributes),
34+
'deletedAt',
35+
);
36+
const PROJECT_PHASE_PRODUCTS_ATTRIBUTES = _.without(
37+
_.keys(models.PhaseProduct.rawAttributes),
38+
'deletedAt',
39+
);
3240

3341

3442
const escapeEsKeyword = keyword => keyword.replace(/[+-=><!|(){}[&\]^"~*?:\\/]/g, '\\\\$&');
@@ -60,6 +68,14 @@ const parseElasticSearchCriteria = (criteria, fields, order) => {
6068
const memberFields = _.get(fields, 'project_members');
6169
sourceInclude = sourceInclude.concat(_.map(memberFields, single => `members.${single}`));
6270
}
71+
if (_.get(fields, 'project_phases', null)) {
72+
const phaseFields = _.get(fields, 'project_phases');
73+
sourceInclude = sourceInclude.concat(_.map(phaseFields, single => `phases.${single}`));
74+
}
75+
if (_.get(fields, 'project_phases_products', null)) {
76+
const phaseFields = _.get(fields, 'project_phases_products');
77+
sourceInclude = sourceInclude.concat(_.map(phaseFields, single => `phases.products.${single}`));
78+
}
6379
sourceInclude = sourceInclude.concat(_.map(PROJECT_ATTACHMENT_ATTRIBUTES, single => `attachments.${single}`));
6480

6581
if (sourceInclude) {
@@ -180,6 +196,8 @@ const retrieveProjects = (req, criteria, sort, ffields) => {
180196
fields = util.parseFields(fields, {
181197
projects: PROJECT_ATTRIBUTES,
182198
project_members: PROJECT_MEMBER_ATTRIBUTES,
199+
project_phases: PROJECT_PHASE_ATTRIBUTES,
200+
project_phases_products: PROJECT_PHASE_PRODUCTS_ATTRIBUTES,
183201
});
184202
// make sure project.id is part of fields
185203
if (_.indexOf(fields.projects, 'id') < 0) {

0 commit comments

Comments
 (0)