Skip to content

Commit

Permalink
ch(validateAndFixBug): Fix bug about Like and Dislike
Browse files Browse the repository at this point in the history
- Validate trip Id on trip stats feature
  • Loading branch information
Willy Sugira authored and Willy Sugira committed Feb 4, 2020
1 parent 31ad6f6 commit 7994c1d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/middlewares/Validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class Validate {
const MaxDate = new Date(year + 20, month, day).toDateString();
return [
check('tripTypeId', 'trip type id should be an integer(1: One-way, 2: two-way, 3: Multi-city)').isInt(),
check('user', 'user should be identified by id of integer type').isInt().optional(),
check('from', 'To date should be valid(YYYY-MM-DD)').isBefore(MaxDate),
check('to', 'End date should be valid(YYYY-MM-DD)').isBefore(MaxDate),
];
Expand Down
2 changes: 1 addition & 1 deletion src/services/AccommodationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class AccommodationService {
displayMessage = like ? 'You liked this accommodation!' : 'You disliked this accommodation!';
}

const updateLikeObject = [setObject, { where: { userId: id } }];
const updateLikeObject = [setObject, { where: { userId: id, accommodationId } }];

await CommonQueries.update(likes, updateLikeObject);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/060-tripTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ describe('User stats for trips in X timeframe', () => {
.get('/api/v1/trips/stats/2?from=2020-01-01&to=2025-12-30&user=b')
.set('token', managerToken)
.end((err, res) => {
expect(res.status).eql(500);
expect(res.body).to.have.property('message', 'invalid input syntax for integer: "b"');
expect(res.status).eql(400);
expect(res.body.message).eql(['user should be identified by id of integer type']);
done(err);
});
});
Expand Down

0 comments on commit 7994c1d

Please sign in to comment.