Skip to content

Commit

Permalink
ft(multi city trip request):
Browse files Browse the repository at this point in the history
create route for multi-city trip request
add validations
create a table model and trips
create routew for posting locations
[Finishes 169258638]
  • Loading branch information
hezzie committed Nov 23, 2019
1 parent 7aa40e7 commit d09ca7b
Show file tree
Hide file tree
Showing 47 changed files with 1,262 additions and 597 deletions.
120 changes: 98 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"express-validator": "^6.2.0",
"http-status-codes": "^1.4.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.15",
"method-override": "^2.3.10",
"methods": "^1.1.2",
"mocha": "^6.2.2",
Expand All @@ -49,6 +50,7 @@
"passport-twitter-token": "^1.3.0",
"pg": "^7.12.1",
"pg-hstore": "^2.3.3",
"pg-native": "^3.0.0",
"request": "^2.87.0",
"sequelize": "^5.21.2",
"sequelize-cli": "^5.5.1",
Expand Down
35 changes: 35 additions & 0 deletions src/controllers/LocationController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import dotenv from 'dotenv';
import Customize from '../helpers/Customize';
import { cities } from '../database/models';
import DataEngine from '../middlewares/DataEngine';

dotenv.config();
/**
* @export
* @class LocationController
*/
class LocationController {
/**
* An admin should be able to add locations
* @static
* @param {object} req request object
* @param {object} res response object
* @memberof LocationController
* @returns {object} data
*/
static async saveLocation(req, res) {
try {
const { name } = req.body;

const newLocation = await cities.create({
city: name
});


return Customize.successMessage(req, res, 'Location posted successfully', newLocation, 201);
} catch (err) {
return Customize.errorMessage(req, res, err.message, 500);
}
}
}
export default LocationController;
47 changes: 44 additions & 3 deletions src/controllers/TripController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import createTripRequest from '../helpers/createTripRequest';
import Customize from '../helpers/Customize';
import { tripRequest, users } from '../database/models';
import ControllerHelper from '../helpers/ControllerHelper';
import emailHelper from '../helpers/EmailHelper';


/**
* @export
Expand All @@ -7,14 +11,15 @@ import createTripRequest from '../helpers/createTripRequest';
class TripController {
/**
* User can be able to request one-way trip
* User can be able to request multi-city trip
* @static
* @param {object} req request object
* @param {object} res response object
* @memberof TripController
* @returns {object} data
*/
static async OneWayTripController(req, res) {
createTripRequest(req, res, 1);
ControllerHelper.tripControllerHelper(req, res, 1);
}

/**
Expand All @@ -26,7 +31,43 @@ class TripController {
* @returns {object} data
*/
static async returnTripController(req, res) {
createTripRequest(req, res, 2);
ControllerHelper.tripControllerHelper(req, res, 2);
}

/**
* User can be able to request one-way trip
* User can be able to request multi-city trip
* @static
* @param {object} req request object
* @param {object} res response object
* @memberof TripController
* @returns {object} data
*/
static async requestTrip(req, res) {
ControllerHelper.tripControllerHelper(req, res, 3);
}

/**
* Manager should be able to approve a trip
* @static
* @param {object} req request object
* @param {object} res response object
* @memberof UserController
* @returns {object} data
*/
static async approveTrip(req, res) {
try {
const user = await users.findOne({ where: { id: req.row.userId }, raw: true });
emailHelper.approvedEmailHelper(user);
await tripRequest.update({ statusId: 2 }, {
where: {
id: req.params.id
}
});
return Customize.successMessage(req, res, 'Your request has been approved', '', 201);
} catch (err) {
return Customize.errorMessage(req, res, err.message, 500);
}
}
}

Expand Down
Loading

0 comments on commit d09ca7b

Please sign in to comment.