Skip to content

Commit 74d5a0d

Browse files
committed
fix formating
1 parent fc4dda0 commit 74d5a0d

File tree

5 files changed

+217
-220
lines changed

5 files changed

+217
-220
lines changed

src/models/milestone.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ module.exports = (sequelize, DataTypes) => {
9191
comment: null,
9292
createdBy: milestone.createdBy,
9393
updatedBy: milestone.updatedBy,
94-
},
95-
{
96-
transaction: options.transaction,
97-
}),
94+
}, {
95+
transaction: options.transaction,
96+
}),
97+
9898
afterUpdate: (milestone, options) => {
9999
if (milestone.changed().includes('status')) {
100100
return models.StatusHistory.create({
@@ -104,10 +104,9 @@ module.exports = (sequelize, DataTypes) => {
104104
comment: options.comment || null,
105105
createdBy: milestone.createdBy,
106106
updatedBy: milestone.updatedBy,
107-
},
108-
{
109-
transaction: options.transaction,
110-
});
107+
}, {
108+
transaction: options.transaction,
109+
});
111110
}
112111
return Promise.resolve();
113112
},

src/routes/milestones/status.pause.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import models from '../../models';
99

1010
const permissions = tcMiddleware.permissions;
1111

12-
1312
const schema = {
1413
params: {
1514
timelineId: Joi.number().integer().positive().required(),
@@ -24,8 +23,8 @@ const schema = {
2423

2524
module.exports = [
2625
validate(schema),
27-
// Validate and get projectId from the timelineId param,
28-
// and set to request params for checking by the permissions middleware
26+
// Validate and get projectId from the timelineId param,
27+
// and set to request params for checking by the permissions middleware
2928
validateTimeline.validateTimelineIdParam,
3029
permissions('milestone.edit'),
3130
(req, res, next) => {
@@ -43,45 +42,45 @@ module.exports = [
4342
let updated;
4443

4544
return models.sequelize.transaction(transaction =>
46-
// Find the milestone
47-
models.Milestone.findOne({ where })
48-
.then((milestone) => {
49-
// Not found
50-
if (!milestone) {
51-
const apiErr = new Error(`Milestone not found for milestone id ${req.params.milestoneId}`);
52-
apiErr.status = 404;
53-
return Promise.reject(apiErr);
54-
}
45+
// Find the milestone
46+
models.Milestone.findOne({ where })
47+
.then((milestone) => {
48+
// Not found
49+
if (!milestone) {
50+
const apiErr = new Error(`Milestone not found for milestone id ${req.params.milestoneId}`);
51+
apiErr.status = 404;
52+
return Promise.reject(apiErr);
53+
}
5554

56-
// status already on pause
57-
if (milestone.status === MILESTONE_STATUS.PAUSED) {
58-
const apiErr = new Error('Milestone status already paused');
59-
apiErr.status = 422;
60-
return Promise.reject(apiErr);
61-
}
55+
// status already on pause
56+
if (milestone.status === MILESTONE_STATUS.PAUSED) {
57+
const apiErr = new Error('Milestone status already paused');
58+
apiErr.status = 422;
59+
return Promise.reject(apiErr);
60+
}
6261

63-
original = _.omit(milestone.toJSON(), ['deletedAt', 'deletedBy']);
62+
original = _.omit(milestone.toJSON(), ['deletedAt', 'deletedBy']);
6463

65-
entityToUpdate.status = MILESTONE_STATUS.PAUSED;
66-
entityToUpdate.id = milestone.id;
64+
entityToUpdate.status = MILESTONE_STATUS.PAUSED;
65+
entityToUpdate.id = milestone.id;
6766

68-
// Update
69-
return milestone.update(entityToUpdate, { comment, transaction });
70-
})
67+
// Update
68+
return milestone.update(entityToUpdate, { comment, transaction });
69+
})
7170
.then((updatedMilestone) => {
7271
updated = _.omit(updatedMilestone.toJSON(), 'deletedAt', 'deletedBy');
7372
}),
74-
)
73+
)
7574
.then(() => {
7675
// Send event to bus
7776
req.log.debug('Sending event to RabbitMQ bus for milestone %d', updated.id);
7877
req.app.services.pubsub.publish(BUS_API_EVENT.MILESTONE_TRANSITION_PAUSED,
79-
{ original, updated },
80-
{ correlationId: req.id },
78+
{ original, updated },
79+
{ correlationId: req.id },
8180
);
8281

8382
req.app.emit(BUS_API_EVENT.MILESTONE_TRANSITION_PAUSED,
84-
{ req, original, updated });
83+
{ req, original, updated });
8584

8685
res.json(util.wrapResponse(req.id));
8786
return Promise.resolve(true);

src/routes/milestones/status.pause.spec.js

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -271,124 +271,124 @@ describe('Status Pause Milestone', () => {
271271

272272
it('should return 403 for member who is not in the project', (done) => {
273273
request(server)
274-
.patch('/v4/timelines/1/milestones/1/status/pause')
275-
.set({
276-
Authorization: `Bearer ${testUtil.jwts.member2}`,
277-
})
278-
.send(body)
279-
.expect(403, done);
274+
.patch('/v4/timelines/1/milestones/1/status/pause')
275+
.set({
276+
Authorization: `Bearer ${testUtil.jwts.member2}`,
277+
})
278+
.send(body)
279+
.expect(403, done);
280280
});
281281

282282
it('should return 404 for non-existed timeline', (done) => {
283283
request(server)
284-
.patch('/v4/timelines/1234/milestones/1/status/pause')
285-
.send(body)
286-
.set({
287-
Authorization: `Bearer ${testUtil.jwts.admin}`,
288-
})
289-
.expect(404, done);
284+
.patch('/v4/timelines/1234/milestones/1/status/pause')
285+
.send(body)
286+
.set({
287+
Authorization: `Bearer ${testUtil.jwts.admin}`,
288+
})
289+
.expect(404, done);
290290
});
291291

292292
it('should return 404 for deleted timeline', (done) => {
293293
request(server)
294-
.patch('/v4/timelines/3/milestones/1/status/pause')
295-
.send(body)
296-
.set({
297-
Authorization: `Bearer ${testUtil.jwts.admin}`,
298-
})
299-
.expect(404, done);
294+
.patch('/v4/timelines/3/milestones/1/status/pause')
295+
.send(body)
296+
.set({
297+
Authorization: `Bearer ${testUtil.jwts.admin}`,
298+
})
299+
.expect(404, done);
300300
});
301301

302302
it('should return 404 for non-existed Milestone', (done) => {
303303
request(server)
304-
.patch('/v4/timelines/1/milestones/111/status/pause')
305-
.send(body)
306-
.set({
307-
Authorization: `Bearer ${testUtil.jwts.admin}`,
308-
})
309-
.expect(404, done);
304+
.patch('/v4/timelines/1/milestones/111/status/pause')
305+
.send(body)
306+
.set({
307+
Authorization: `Bearer ${testUtil.jwts.admin}`,
308+
})
309+
.expect(404, done);
310310
});
311311

312312
it('should return 404 for deleted Milestone', (done) => {
313313
request(server)
314-
.patch('/v4/timelines/1/milestones/5/status/pause')
315-
.send(body)
316-
.set({
317-
Authorization: `Bearer ${testUtil.jwts.admin}`,
318-
})
319-
.expect(404, done);
314+
.patch('/v4/timelines/1/milestones/5/status/pause')
315+
.send(body)
316+
.set({
317+
Authorization: `Bearer ${testUtil.jwts.admin}`,
318+
})
319+
.expect(404, done);
320320
});
321321

322322
it('should return 422 for invalid timelineId param', (done) => {
323323
request(server)
324-
.patch('/v4/timelines/0/milestones/1/status/pause')
325-
.send(body)
326-
.set({
327-
Authorization: `Bearer ${testUtil.jwts.admin}`,
328-
})
329-
.expect(422, done);
324+
.patch('/v4/timelines/0/milestones/1/status/pause')
325+
.send(body)
326+
.set({
327+
Authorization: `Bearer ${testUtil.jwts.admin}`,
328+
})
329+
.expect(422, done);
330330
});
331331

332332
it('should return 422 for invalid milestoneId param', (done) => {
333333
request(server)
334-
.patch('/v4/timelines/1/milestones/0/status/pause')
335-
.send(body)
336-
.set({
337-
Authorization: `Bearer ${testUtil.jwts.admin}`,
338-
})
339-
.expect(422, done);
334+
.patch('/v4/timelines/1/milestones/0/status/pause')
335+
.send(body)
336+
.set({
337+
Authorization: `Bearer ${testUtil.jwts.admin}`,
338+
})
339+
.expect(422, done);
340340
});
341341

342342
it('should return 422 for missing comment', (done) => {
343343
const partialBody = _.cloneDeep(body);
344344
delete partialBody.param.comment;
345345
request(server)
346-
.patch('/v4/timelines/1/milestones/1/status/pause')
347-
.set({
348-
Authorization: `Bearer ${testUtil.jwts.admin}`,
349-
})
350-
.send(partialBody)
351-
.expect(422, done);
346+
.patch('/v4/timelines/1/milestones/1/status/pause')
347+
.set({
348+
Authorization: `Bearer ${testUtil.jwts.admin}`,
349+
})
350+
.send(partialBody)
351+
.expect(422, done);
352352
});
353353

354354
it('should return 200 and status should update to paused', (done) => {
355355
request(server)
356-
.patch('/v4/timelines/1/milestones/1/status/pause')
357-
.set({
358-
Authorization: `Bearer ${testUtil.jwts.admin}`,
359-
})
360-
.send(body)
361-
.expect(200)
362-
.end(() => {
363-
models.Milestone.findById(1)
364-
.then((milestone) => {
365-
milestone.status.should.be.eql('paused');
366-
done();
367-
});
356+
.patch('/v4/timelines/1/milestones/1/status/pause')
357+
.set({
358+
Authorization: `Bearer ${testUtil.jwts.admin}`,
359+
})
360+
.send(body)
361+
.expect(200)
362+
.end(() => {
363+
models.Milestone.findById(1)
364+
.then((milestone) => {
365+
milestone.status.should.be.eql('paused');
366+
done();
368367
});
368+
});
369369
});
370370

371371
it('should have one status history created with multiple sequencial status paused messages', function fn(done) {
372372
this.timeout(10000);
373373
request(server)
374-
.patch('/v4/timelines/1/milestones/1/status/pause')
375-
.set({
376-
Authorization: `Bearer ${testUtil.jwts.admin}`,
377-
})
378-
.send(body)
379-
.expect(200)
380-
.end(() => {
381-
request(server)
382-
.patch('/v4/timelines/1/milestones/1/status/pause')
383-
.set({
384-
Authorization: `Bearer ${testUtil.jwts.admin}`,
385-
})
386-
.send(body)
387-
.expect(422)
388-
.end(() => {
389-
done();
390-
});
391-
});
374+
.patch('/v4/timelines/1/milestones/1/status/pause')
375+
.set({
376+
Authorization: `Bearer ${testUtil.jwts.admin}`,
377+
})
378+
.send(body)
379+
.expect(200)
380+
.end(() => {
381+
request(server)
382+
.patch('/v4/timelines/1/milestones/1/status/pause')
383+
.set({
384+
Authorization: `Bearer ${testUtil.jwts.admin}`,
385+
})
386+
.send(body)
387+
.expect(422)
388+
.end(() => {
389+
done();
390+
});
391+
});
392392
});
393393
});
394394
});

0 commit comments

Comments
 (0)