-
Notifications
You must be signed in to change notification settings - Fork 2
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
#168781708-user can book an accommodation #32
Conversation
} | ||
} | ||
}).then(accommodation => responseUtil(res, 200, | ||
strings.accommodation.success.AVAILABLE, accommodation)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected a newline before ')' function-paren-newline
[Op.gt]: 0, | ||
} | ||
} | ||
}).then(accommodation => responseUtil(res, 200, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected a newline after '(' function-paren-newline
9bf244c
to
8a1197c
Compare
}] | ||
}).then(accommodation => responseUtil( | ||
res, 200, strings.accommodation.success.AVAILABLE, accommodation | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected newline before ')' function-paren-newline
include: [{ | ||
model: models.locations, as: 'accommodationLocation', attributes: ['id', 'name'] | ||
}] | ||
}).then(accommodation => responseUtil( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected newline after '(' function-paren-newline
1b598f1
to
30dd8a0
Compare
} | ||
|
||
// book an accomodation | ||
static BookAccommdation(req, res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow naming convention we use
30dd8a0
to
91c0523
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job @sabin18 . However, please ensure that you make the necessary validations. For example, I can book an accommodation with dates that have already passed. Please look into that. Also, the error messages returned on the wrong date formats should be a date format not a date itself.
91c0523
to
9ccf250
Compare
[Op.gt]: 0, | ||
} | ||
}, | ||
attributes: { exclude: ['locationId', 'owner'] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the owner object to the response
static bookAccommdation(req, res) { | ||
const { Op } = sequelize; | ||
const { id } = req.params; | ||
const { checkInDate, checkOutDate } = req.body; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add accomodationId
and numberRooms
to the req.body
} | ||
if (moment(checkOutDate) < moment(checkInDate)) { | ||
return responseUtil(res, 400, strings.accommodation.error.DATE_ERROR); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a helper function to be reused
if (accommodation.length === 0) { | ||
return responseUtil(res, 400, strings.accommodation.error.NOT_AVAILABLE); | ||
} | ||
if (moment(checkOutDate) < moment.now() || moment(checkOutDate) < moment.now()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a helper function to be reused
src/routes/api/accommodations.js
Outdated
deleteAccommodation, | ||
availableAccommdation, | ||
bookAccommdation | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this line
src/routes/api/accommodations.js
Outdated
@@ -190,5 +193,7 @@ router.post('/', validateToken, checkSupplierRole, catchEmptyForm, multipartMidd | |||
router.get('/', validateToken, getAllAccommodations); | |||
router.patch('/:id/edit', validateToken, checkId, catchEmptyForm, multipartMiddleware, isAccommodationFound, isOwner, validateAccommodationEdit, editAccommodation); | |||
router.delete('/:id/delete', validateToken, checkId, isAccommodationFound, isOwner, deleteAccommodation); | |||
router.get('/available', validateToken, availableAccommdation); | |||
router.patch('/booking/:id', validateToken, checkId, validateDate, bookAccommdation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this route to /book
and remove the param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job @sabin18, I have left comments on this pr. Also kindly add a route /bookings
that will allow users to view their bookings
9ccf250
to
2fd3534
Compare
models.booking.create(bookingData); | ||
const remainingSpace = parseInt(accommodation[0].availableSpace) - roomsNumber; | ||
models.accommodations.update({ availableSpace: remainingSpace, }, | ||
{ where: { id: accomodationId, }, }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected a newline before ')' function-paren-newline
} | ||
models.booking.create(bookingData); | ||
const remainingSpace = parseInt(accommodation[0].availableSpace) - roomsNumber; | ||
models.accommodations.update({ availableSpace: remainingSpace, }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected a newline after '(' function-paren-newline
2fd3534
to
2670161
Compare
const remainingSpace = parseInt(accommodation[0].availableSpace) - roomsNumber; | ||
models.accommodations.update( | ||
{ availableSpace: remainingSpace, }, { where: { id: accomodationId, }, } | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected newline before ')' function-paren-newline
} | ||
models.booking.create(bookingData); | ||
const remainingSpace = parseInt(accommodation[0].availableSpace) - roomsNumber; | ||
models.accommodations.update( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected newline after '(' function-paren-newline
51e1c59
to
851321a
Compare
7cc0d3e
to
d0dcf51
Compare
add view all available accommodation add booking function [finishes #168781708]
d0dcf51
to
5b7cb57
Compare
What does this PR do?
Description of Task to be completed?
How should this be manually tested?
GET: /api/v1/accommodations/available
GET: /api/v1/accommodations/bookings
PATCH:/api/v1/accommodations/book
Any background context you want to provide?
N/A
What are the relevant pivotal tracker stories?
168781708
Screenshots (if appropriate)
Questions:
N/A