-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#167727336] Feature (user book accommodation)
- Loading branch information
1 parent
76251e9
commit d1ce785
Showing
38 changed files
with
1,590 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ dist | |
package-lock.json | ||
.nyc_output/ | ||
coverage/ | ||
npm-debug.log |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as bookingServices from '../services/bookingServices'; | ||
import { respondWithSuccess, respondWithWarning } from '../helpers/responseHandler'; | ||
import statusCode from '../helpers/statusCode'; | ||
|
||
/* | ||
* Function creates booking | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns {object} response object | ||
*/ | ||
export const createBooking = async (req, res) => { | ||
try { | ||
const data = { | ||
...req.body, | ||
userId: req.auth.id, | ||
}; | ||
const booking = await bookingServices.create(data); | ||
|
||
return respondWithSuccess(res, statusCode.created, 'resource successfully created', booking.toJSON()); | ||
} catch (error) { | ||
return respondWithWarning(res, statusCode.internalServerError, 'Server Error'); | ||
} | ||
}; | ||
|
||
/** | ||
* Function gets all bookings | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns {object} response object | ||
*/ | ||
export const getAllBookings = async (req, res) => { | ||
try { | ||
const bookings = await bookingServices.findAllBookings(); | ||
if (!bookings) { | ||
return respondWithWarning(res, statusCode.resourceNotFound, 'resource not found'); | ||
} | ||
return respondWithSuccess(res, statusCode.success, 'resource successfully fetched', bookings); | ||
} catch (error) { | ||
return respondWithWarning(res, statusCode.internalServerError, 'Server Error'); | ||
} | ||
}; | ||
|
||
/** | ||
* Function gets one booking for a requester | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns {object} response object | ||
*/ | ||
export const getUserBookings = async (req, res) => { | ||
const { id } = req.auth; | ||
try { | ||
const bookings = await bookingServices.findUserBookings(id); | ||
if (!bookings) { | ||
return respondWithWarning(res, statusCode.resourceNotFound, 'resource not found'); | ||
} | ||
return respondWithSuccess(res, statusCode.success, 'resource successfully fetched', bookings); | ||
} catch (error) { | ||
return respondWithWarning(res, statusCode.internalServerError, 'Server Error'); | ||
} | ||
}; | ||
|
||
/** | ||
* Function gets one booking | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns {object} response object | ||
*/ | ||
export const getOneBooking = async (req, res) => { | ||
try { | ||
const { bookingId } = req.params; | ||
const booking = await bookingServices.findOneBooking(parseInt(bookingId, 10)); | ||
if (!booking) { | ||
return respondWithWarning(res, statusCode.resourceNotFound, 'resource not found'); | ||
} | ||
return respondWithSuccess(res, statusCode.success, 'resource successfully fetched', booking.toJSON()); | ||
} catch (error) { | ||
return respondWithWarning(res, statusCode.internalServerError, 'Server Error'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.