|
| 1 | +"use strict"; |
| 2 | +const Constants = { |
| 3 | + Success: require("../constants/success.constant"), |
| 4 | + Error: require("../constants/error.constant") |
| 5 | +}; |
| 6 | + |
| 7 | +function okay(req, res) { |
| 8 | + return res.status(200).json({ |
| 9 | + message: "good" |
| 10 | + }); |
| 11 | +} |
| 12 | + |
| 13 | +/** |
| 14 | + * @function showTravel |
| 15 | + * @param {{body: {travel: Object}}} req |
| 16 | + * @param {*} res |
| 17 | + * @return {JSON} Success status and travel object |
| 18 | + * @description Returns the JSON of travel object located in req.body.travel |
| 19 | + */ |
| 20 | +function showTravel(req, res) { |
| 21 | + return res.status(200).json({ |
| 22 | + message: Constants.Success.TRAVEL_READ, |
| 23 | + data: req.body.travel.toJSON() |
| 24 | + }); |
| 25 | +} |
| 26 | + |
| 27 | +/** |
| 28 | + * @function createTravel |
| 29 | + * @param {{body: {travel: {_id: ObjectId, accountId: ObjectId, hackerId: objectId, status: string, request: number, offer: number}}}} req |
| 30 | + * @param {*} res |
| 31 | + * @return {JSON} Success status |
| 32 | + * @description |
| 33 | + * Create a travel's record based off information stored in req.body.travel |
| 34 | + * Returns a 200 status for the created travel. |
| 35 | + */ |
| 36 | +function createdTravel(req, res) { |
| 37 | + return res.status(200).json({ |
| 38 | + message: Constants.Success.TRAVEL_CREATE, |
| 39 | + data: req.body.travel.toJSON() |
| 40 | + }); |
| 41 | +} |
| 42 | + |
| 43 | +/** |
| 44 | + * @function updatedTravel |
| 45 | + * @param {{params: {id: ObjectId}, body: {Object}}} req |
| 46 | + * @param {*} res |
| 47 | + * @return {JSON} Success or error status |
| 48 | + * @description |
| 49 | + * Change a travel's information based on the trave;'s mongoID specified in req.params.id. |
| 50 | + * The id is moved to req.body.id from req.params.id by validation. |
| 51 | + * Returns a 200 status for an updated travel. |
| 52 | + * The new information is located in req.body. |
| 53 | + */ |
| 54 | +function updatedTravel(req, res) { |
| 55 | + return res.status(200).json({ |
| 56 | + message: Constants.Success.TRAVEL_UPDATE, |
| 57 | + data: req.body |
| 58 | + }); |
| 59 | +} |
| 60 | + |
| 61 | +module.exports = { |
| 62 | + okay: okay, |
| 63 | + showTravel: showTravel, |
| 64 | + updatedTravel: updatedTravel, |
| 65 | + createdTravel: createdTravel |
| 66 | +}; |
0 commit comments