Skip to content
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

Merged
merged 1 commit into from
Oct 28, 2019

Conversation

sabin18
Copy link
Collaborator

@sabin18 sabin18 commented Oct 24, 2019

What does this PR do?

  • It allow user to view all available accommodations and book an accommodation.

Description of Task to be completed?

  • add view all available accommodation function
  • add booking function
  • add view all booking made by the user function

How should this be manually tested?

  • clone the repository : git clone https://github.com/andela/caret-bn-backend.git
  • checkout to branch ft-book-accommodation-168781708
  • run sequelize db:migrate
  • run sequelize db:seed:all
  • Login
  • Take the token to your headers in authorization as Bearer Token to each routes of this feature
  • use this route to view all available accommodations GET: /api/v1/accommodations/available
  • use this route to view all your bookings GET: /api/v1/accommodations/bookings
  • use this route to book an accommodation PATCH:/api/v1/accommodations/book
  • on booking an accommodation you add the Id of accommodation in the body.

Any background context you want to provide?

N/A

What are the relevant pivotal tracker stories?

168781708

Screenshots (if appropriate)

Screen Shot 2019-10-28 at 10 34 44

Screen Shot 2019-10-28 at 10 35 11

Screen Shot 2019-10-28 at 10 35 32

Questions:

N/A

}
}
}).then(accommodation => responseUtil(res, 200,
strings.accommodation.success.AVAILABLE, accommodation));
Copy link

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,
Copy link

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

@sabin18 sabin18 added the WIP Work In Progress label Oct 24, 2019
@sabin18 sabin18 changed the title #168781708-user can book accommodation #168781708-user can book an accommodation Oct 24, 2019
@sabin18 sabin18 force-pushed the ft-book-accommodation-168781708 branch 2 times, most recently from 9bf244c to 8a1197c Compare October 24, 2019 09:55
}]
}).then(accommodation => responseUtil(
res, 200, strings.accommodation.success.AVAILABLE, accommodation
));
Copy link

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(
Copy link

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

@sabin18 sabin18 force-pushed the ft-book-accommodation-168781708 branch 3 times, most recently from 1b598f1 to 30dd8a0 Compare October 24, 2019 11:06
@sabin18 sabin18 added Ready For Review and removed WIP Work In Progress labels Oct 24, 2019
}

// book an accomodation
static BookAccommdation(req, res) {
Copy link
Collaborator

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

@sabin18 sabin18 force-pushed the ft-book-accommodation-168781708 branch from 30dd8a0 to 91c0523 Compare October 24, 2019 12:42
Copy link
Contributor

@alainmateso alainmateso left a 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.

@sabin18 sabin18 force-pushed the ft-book-accommodation-168781708 branch from 91c0523 to 9ccf250 Compare October 24, 2019 17:37
@alainmateso alainmateso self-requested a review October 25, 2019 06:54
[Op.gt]: 0,
}
},
attributes: { exclude: ['locationId', 'owner'] },
Copy link
Contributor

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;
Copy link
Contributor

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);
}
Copy link
Contributor

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()) {
Copy link
Contributor

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

deleteAccommodation,
availableAccommdation,
bookAccommdation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

@@ -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);
Copy link
Contributor

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

Copy link
Contributor

@nakiwuge nakiwuge left a 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

@sabin18 sabin18 added WIP Work In Progress and removed Ready For Review labels Oct 26, 2019
@sabin18 sabin18 force-pushed the ft-book-accommodation-168781708 branch from 9ccf250 to 2fd3534 Compare October 27, 2019 19:18
models.booking.create(bookingData);
const remainingSpace = parseInt(accommodation[0].availableSpace) - roomsNumber;
models.accommodations.update({ availableSpace: remainingSpace, },
{ where: { id: accomodationId, }, });
Copy link

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, },
Copy link

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

@sabin18 sabin18 force-pushed the ft-book-accommodation-168781708 branch from 2fd3534 to 2670161 Compare October 27, 2019 19:47
const remainingSpace = parseInt(accommodation[0].availableSpace) - roomsNumber;
models.accommodations.update(
{ availableSpace: remainingSpace, }, { where: { id: accomodationId, }, }
);
Copy link

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(
Copy link

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

@sabin18 sabin18 force-pushed the ft-book-accommodation-168781708 branch 3 times, most recently from 51e1c59 to 851321a Compare October 28, 2019 08:18
@sabin18 sabin18 added Ready For Review and removed WIP Work In Progress labels Oct 28, 2019
@sabin18 sabin18 force-pushed the ft-book-accommodation-168781708 branch 3 times, most recently from 7cc0d3e to d0dcf51 Compare October 28, 2019 15:24
add view all available accommodation
add booking function
[finishes #168781708]
@sabin18 sabin18 force-pushed the ft-book-accommodation-168781708 branch from d0dcf51 to 5b7cb57 Compare October 28, 2019 15:56
@nakiwuge nakiwuge merged commit 9b88d11 into develop Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants