Skip to content

Commit 8fb8b2f

Browse files
committed
Fix remaining mismatches (productCategories, projectTemplates, projectSettings, projectReports)
1 parent 0718a23 commit 8fb8b2f

File tree

9 files changed

+129
-137
lines changed

9 files changed

+129
-137
lines changed

src/routes/productCategories/create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = [
4343
return models.ProductCategory.findByPk(req.body.key, { paranoid: false })
4444
.then((existing) => {
4545
if (existing) {
46-
const apiErr = new Error(`Product category already exists for key ${req.params.key}`);
46+
const apiErr = new Error(`Product category already exists (may be deleted) for key ${req.body.key}`);
4747
apiErr.status = 400;
4848
return Promise.reject(apiErr);
4949
}

src/routes/projectReports/getReport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = [
4747
}
4848

4949
req.log.debug(result);
50-
return res.status(200).json(util.wrapResponse(req.id, result));
50+
return res.status(200).json(result);
5151
} catch (err) {
5252
req.log.error(err);
5353
return res.status(500).send(err.toString());

src/routes/projectSettings/create.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@ const schema = {
1515
params: {
1616
projectId: Joi.number().integer().positive().required(),
1717
},
18-
body: {
19-
param: Joi.object().keys({
20-
key: Joi.string().max(255).required(),
21-
value: Joi.string().max(255).required(),
22-
valueType: Joi.string().valid(_.values(VALUE_TYPE)).required(),
23-
projectId: Joi.any().strip(),
24-
metadata: Joi.object().optional(),
25-
readPermission: Joi.object().required(),
26-
writePermission: Joi.object().required(),
27-
}).required(),
28-
},
18+
body: Joi.object().keys({
19+
key: Joi.string().max(255).required(),
20+
value: Joi.string().max(255).required(),
21+
valueType: Joi.string().valid(_.values(VALUE_TYPE)).required(),
22+
projectId: Joi.any().strip(),
23+
metadata: Joi.object().optional(),
24+
readPermission: Joi.object().required(),
25+
writePermission: Joi.object().required(),
26+
}).required(),
2927
};
3028

3129
module.exports = [
@@ -34,7 +32,7 @@ module.exports = [
3432
(req, res, next) => {
3533
let setting = null;
3634
const projectId = req.params.projectId;
37-
const entity = _.assign(req.body.param, {
35+
const entity = _.assign(req.body, {
3836
createdBy: req.authUser.userId,
3937
updatedBy: req.authUser.userId,
4038
projectId,
@@ -55,15 +53,15 @@ module.exports = [
5553
includeAllProjectSettingsForInternalUsage: true,
5654
where: {
5755
projectId,
58-
key: req.body.param.key,
56+
key: req.body.key,
5957
},
6058
paranoid: false,
6159
});
6260
})
6361
.then((projectSetting) => {
6462
if (projectSetting) {
6563
const apiErr = new Error(`Project Setting already exists for project id ${projectId} ` +
66-
`and key ${req.body.param.key}`);
64+
`and key ${req.body.key}`);
6765
apiErr.status = 400;
6866
return Promise.reject(apiErr);
6967
}
@@ -86,8 +84,7 @@ module.exports = [
8684
req.log.debug('new project setting created (id# %d, key: %s)',
8785
setting.id, setting.key);
8886
// Omit deletedAt, deletedBy
89-
res.status(201).json(util.wrapResponse(
90-
req.id, _.omit(setting.toJSON(), 'deletedAt', 'deletedBy'), 1, 201));
87+
res.status(201).json(_.omit(setting.toJSON(), 'deletedAt', 'deletedBy'));
9188
})
9289
.catch(next);
9390
},

src/routes/projectSettings/create.spec.js

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,16 @@ describe('CREATE Project Setting', () => {
7474
let estimationId;
7575

7676
const body = {
77-
param: {
78-
key: 'markup_topcoder_service',
79-
value: '3500',
80-
valueType: 'double',
81-
readPermission: {
82-
projectRoles: ['customer'],
83-
topcoderRoles: ['administrator'],
84-
},
85-
writePermission: {
86-
allowRule: { topcoderRoles: ['administrator'] },
87-
denyRule: { projectRoles: ['copilot'] },
88-
},
77+
key: 'markup_topcoder_service',
78+
value: '3500',
79+
valueType: 'double',
80+
readPermission: {
81+
projectRoles: ['customer'],
82+
topcoderRoles: ['administrator'],
83+
},
84+
writePermission: {
85+
allowRule: { topcoderRoles: ['administrator'] },
86+
denyRule: { projectRoles: ['copilot'] },
8987
},
9088
};
9189

@@ -175,7 +173,7 @@ describe('CREATE Project Setting', () => {
175173

176174
it('should return 400 for missing key', (done) => {
177175
const invalidBody = _.cloneDeep(body);
178-
delete invalidBody.param.key;
176+
delete invalidBody.key;
179177

180178
request(server)
181179
.post(`/v5/projects/${projectId}/settings`)
@@ -189,7 +187,7 @@ describe('CREATE Project Setting', () => {
189187

190188
it('should return 400 for missing value', (done) => {
191189
const invalidBody = _.cloneDeep(body);
192-
delete invalidBody.param.value;
190+
delete invalidBody.value;
193191

194192
request(server)
195193
.post(`/v5/projects/${projectId}/settings`)
@@ -203,7 +201,7 @@ describe('CREATE Project Setting', () => {
203201

204202
it('should return 400 for missing valueType', (done) => {
205203
const invalidBody = _.cloneDeep(body);
206-
delete invalidBody.param.valueType;
204+
delete invalidBody.valueType;
207205

208206
request(server)
209207
.post(`/v5/projects/${projectId}/settings`)
@@ -217,8 +215,8 @@ describe('CREATE Project Setting', () => {
217215

218216
xit('should return 400 for negative value when valueType = percentage', (done) => {
219217
const invalidBody = _.cloneDeep(body);
220-
invalidBody.param.value = '-10';
221-
invalidBody.param.valueType = VALUE_TYPE.PERCENTAGE;
218+
invalidBody.value = '-10';
219+
invalidBody.valueType = VALUE_TYPE.PERCENTAGE;
222220

223221
request(server)
224222
.post(`/v5/projects/${projectId}/settings`)
@@ -232,8 +230,8 @@ describe('CREATE Project Setting', () => {
232230

233231
xit('should return 400 for value greater than 100 when valueType = percentage', (done) => {
234232
const invalidBody = _.cloneDeep(body);
235-
invalidBody.param.value = '150';
236-
invalidBody.param.valueType = VALUE_TYPE.PERCENTAGE;
233+
invalidBody.value = '150';
234+
invalidBody.valueType = VALUE_TYPE.PERCENTAGE;
237235

238236
request(server)
239237
.post(`/v5/projects/${projectId}/settings`)
@@ -247,11 +245,11 @@ describe('CREATE Project Setting', () => {
247245

248246
it('should return 400, for admin, when create key with existing key', (done) => {
249247
const existing = _.cloneDeep(body);
250-
existing.param.projectId = projectId;
251-
existing.param.createdBy = 1;
252-
existing.param.updatedBy = 1;
248+
existing.projectId = projectId;
249+
existing.createdBy = 1;
250+
existing.updatedBy = 1;
253251

254-
models.ProjectSetting.create(existing.param).then(() => {
252+
models.ProjectSetting.create(existing).then(() => {
255253
request(server)
256254
.post(`/v5/projects/${projectId}/settings`)
257255
.set({
@@ -265,7 +263,7 @@ describe('CREATE Project Setting', () => {
265263
it('should return 201 for manager with non-estimation type, not calculating project estimation items',
266264
(done) => {
267265
const createBody = _.cloneDeep(body);
268-
createBody.param.key = 'markup_no_estimation';
266+
createBody.key = 'markup_no_estimation';
269267

270268
request(server)
271269
.post(`/v5/projects/${projectId}/settings`)
@@ -278,10 +276,10 @@ describe('CREATE Project Setting', () => {
278276
.end((err, res) => {
279277
if (err) done(err);
280278

281-
const resJson = res.body.result.content;
282-
resJson.key.should.be.eql(createBody.param.key);
283-
resJson.value.should.be.eql(createBody.param.value);
284-
resJson.valueType.should.be.eql(createBody.param.valueType);
279+
const resJson = res.body;
280+
resJson.key.should.be.eql(createBody.key);
281+
resJson.value.should.be.eql(createBody.value);
282+
resJson.valueType.should.be.eql(createBody.valueType);
285283
resJson.projectId.should.be.eql(projectId);
286284
resJson.createdBy.should.be.eql(40051334);
287285
should.exist(resJson.createdAt);
@@ -305,10 +303,10 @@ describe('CREATE Project Setting', () => {
305303
.end((err, res) => {
306304
if (err) done(err);
307305

308-
const resJson = res.body.result.content;
309-
resJson.key.should.be.eql(body.param.key);
310-
resJson.value.should.be.eql(body.param.value);
311-
resJson.valueType.should.be.eql(body.param.valueType);
306+
const resJson = res.body;
307+
resJson.key.should.be.eql(body.key);
308+
resJson.value.should.be.eql(body.value);
309+
resJson.valueType.should.be.eql(body.valueType);
312310
resJson.projectId.should.be.eql(projectId);
313311
resJson.createdBy.should.be.eql(40051334);
314312
should.exist(resJson.createdAt);
@@ -318,9 +316,9 @@ describe('CREATE Project Setting', () => {
318316
should.not.exist(resJson.deletedAt);
319317
expectAfterCreate(resJson.id, projectId, _.assign(estimation, {
320318
id: estimationId,
321-
value: body.param.value,
322-
valueType: body.param.valueType,
323-
key: body.param.key,
319+
value: body.value,
320+
valueType: body.valueType,
321+
key: body.key,
324322
}), 1, 0, err, done);
325323
});
326324
});
@@ -337,10 +335,10 @@ describe('CREATE Project Setting', () => {
337335
.end((err, res) => {
338336
if (err) done(err);
339337

340-
const resJson = res.body.result.content;
341-
resJson.key.should.be.eql(body.param.key);
342-
resJson.value.should.be.eql(body.param.value);
343-
resJson.valueType.should.be.eql(body.param.valueType);
338+
const resJson = res.body;
339+
resJson.key.should.be.eql(body.key);
340+
resJson.value.should.be.eql(body.value);
341+
resJson.valueType.should.be.eql(body.valueType);
344342
resJson.projectId.should.be.eql(projectId);
345343
resJson.createdBy.should.be.eql(40051333);
346344
should.exist(resJson.createdAt);
@@ -364,10 +362,10 @@ describe('CREATE Project Setting', () => {
364362
.end((err, res) => {
365363
if (err) done(err);
366364

367-
const resJson = res.body.result.content;
368-
resJson.key.should.be.eql(body.param.key);
369-
resJson.value.should.be.eql(body.param.value);
370-
resJson.valueType.should.be.eql(body.param.valueType);
365+
const resJson = res.body;
366+
resJson.key.should.be.eql(body.key);
367+
resJson.value.should.be.eql(body.value);
368+
resJson.valueType.should.be.eql(body.valueType);
371369
resJson.projectId.should.be.eql(projectId);
372370
resJson.createdBy.should.be.eql(40051336);
373371
resJson.updatedBy.should.be.eql(40051336);

src/routes/projectSettings/list.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import validate from 'express-validation';
66
import Joi from 'joi';
77
import { middleware as tcMiddleware } from 'tc-core-library-js';
88
import models from '../../models';
9-
import util from '../../util';
109

1110
const permissions = tcMiddleware.permissions;
1211

@@ -44,7 +43,7 @@ module.exports = [
4443
return models.ProjectSetting.findAll(options);
4544
})
4645
.then((result) => {
47-
res.json(util.wrapResponse(req.id, _.filter(result, r => r)));
46+
res.json(_.filter(result, r => r));
4847
})
4948
.catch(next);
5049
},

src/routes/projectSettings/list.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe('LIST Project Settings', () => {
159159
if (err) {
160160
done(err);
161161
} else {
162-
const resJson = res.body.result.content;
162+
const resJson = res.body;
163163
should.exist(resJson);
164164
resJson.should.have.lengthOf(0);
165165
done();
@@ -179,7 +179,7 @@ describe('LIST Project Settings', () => {
179179
if (err) {
180180
done(err);
181181
} else {
182-
const resJson = res.body.result.content;
182+
const resJson = res.body;
183183
should.exist(resJson);
184184
resJson.should.have.lengthOf(0);
185185
done();
@@ -198,7 +198,7 @@ describe('LIST Project Settings', () => {
198198
if (err) {
199199
done(err);
200200
} else {
201-
const resJson = res.body.result.content;
201+
const resJson = res.body;
202202
should.exist(resJson);
203203
resJson.should.have.lengthOf(1);
204204
const setting = settings[0];
@@ -225,7 +225,7 @@ describe('LIST Project Settings', () => {
225225
if (err) {
226226
done(err);
227227
} else {
228-
const resJson = res.body.result.content;
228+
const resJson = res.body;
229229
should.exist(resJson);
230230
resJson.should.have.lengthOf(2);
231231
const setting = settings[0];

src/routes/projectSettings/update.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ const schema = {
1616
projectId: Joi.number().integer().positive().required(),
1717
id: Joi.number().integer().positive().required(),
1818
},
19-
body: {
20-
param: Joi.object().keys({
21-
value: Joi.string().max(255),
22-
valueType: Joi.string().valid(_.values(VALUE_TYPE)),
23-
projectId: Joi.any().strip(),
24-
metadata: Joi.object(),
25-
readPermission: Joi.object(),
26-
writePermission: Joi.object(),
27-
}).required(),
28-
},
19+
body: Joi.object().keys({
20+
value: Joi.string().max(255),
21+
valueType: Joi.string().valid(_.values(VALUE_TYPE)),
22+
projectId: Joi.any().strip(),
23+
metadata: Joi.object(),
24+
readPermission: Joi.object(),
25+
writePermission: Joi.object(),
26+
}).required(),
2927
};
3028

3129
module.exports = [
@@ -36,7 +34,7 @@ module.exports = [
3634
let updatedSetting = null;
3735
const projectId = req.params.projectId;
3836
const id = req.params.id;
39-
const entityToUpdate = _.assign(req.body.param, {
37+
const entityToUpdate = _.assign(req.body, {
4038
updatedBy: req.authUser.userId,
4139
});
4240

@@ -69,7 +67,7 @@ module.exports = [
6967
}),
7068
) // transaction end
7169
.then(() => {
72-
res.json(util.wrapResponse(req.id, updatedSetting));
70+
res.json(updatedSetting);
7371
})
7472
.catch(next);
7573
},

0 commit comments

Comments
 (0)