Skip to content

Commit

Permalink
Merge remote-tracking branch 'parent/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
srfrnk committed Feb 18, 2018
2 parents 862751b + d7e75ed commit 1c520cf
Show file tree
Hide file tree
Showing 16 changed files with 1,500 additions and 149 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ As an organization committed to extreme transparency, collaboration, and open-so

For help in getting started, please be sure to read our [contribution guidelines](https://github.com/DAVFoundation/missioncontrol/blob/master/CONTRIBUTING.md).

### License

Licensed under [MIT](https://github.com/DAVFoundation/missioncontrol/blob/master/LICENSE).
3 changes: 3 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"randomstring": "^1.1.5",
"redis": "^2.8.0",
"request": "^2.83.0",
"thrift": "^0.11.0"
"thrift": "^0.11.0",
"body-parser": "^1.18.2"
},
"devDependencies": {
"gulp": "^3.9.1",
Expand Down
2 changes: 1 addition & 1 deletion server/config/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const config = {
requests_ttl: 43200,
needs_ttl: 43200,
bids_ttl: 3600,
vehicles_ttl: 86400,
};
Expand Down
53 changes: 53 additions & 0 deletions server/controllers/NeedController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const {createNeed, getNeed, deleteNeed} = require('../store/needs');
const {deleteBidsForNeed} = require('../store/bids');
const {createMission} = require('../store/missions');
const {updateVehicleStatus} = require('../store/vehicles');
const createConstraints = require('./constraints/need/create');
const validate = require('../lib/validate');

const create = async (req, res) => {
const params = req.body;
const validationErrors = validate(params, createConstraints);
if (validationErrors) {
res.status(422).json(validationErrors);
} else {
const allowedParamsKeys = Object.keys(createConstraints);
Object.keys(params).forEach(key => {if (!allowedParamsKeys.includes(key)) delete params[key];});
params.user_id = req.query.user_id;
const needId = await createNeed(params);
if (needId) {
res.json({needId});
} else {
res.status(500).send('Something broke!');
}
}
};


const cancel = async (req, res) => {
const {needId} = req.params;
const need = await getNeed(needId);
if (need) {
await deleteNeed(need);
await deleteBidsForNeed(need);
res.send('need cancelled');
} else {
res.status(500).send('Something broke!');
}
};

const chooseBid = async (req, res) => {
const {user_id, bid_id} = req.query;
const mission = await createMission({
user_id,
bid_id,
});
if (mission) {
await updateVehicleStatus(mission.vehicle_id, 'contract_received');
res.json({mission});
} else {
res.status(500).send('Something broke!');
}
};

module.exports = {create, cancel, chooseBid};
44 changes: 0 additions & 44 deletions server/controllers/RequestController.js

This file was deleted.

10 changes: 5 additions & 5 deletions server/controllers/StatusController.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const {getVehiclesInRange, updateVehicleStatus, getVehicle, getVehicles, updateVehiclePosition, getPosition, getLatestPositionUpdate} = require('../store/vehicles');
const {getBidsForRequest} = require('../store/bids');
const {getBidsForNeed} = require('../store/bids');
const {getLatestMission, updateMission} = require('../store/missions');
const {createMissionUpdate} = require('../store/mission_updates');
const {hasStore} = require('../lib/environment');
const missionProgress = require('../simulation/missionProgress');
const {calculateNextCoordinate} = require('../simulation/vehicles');

const getStatus = async (req, res) => {
const {lat, long, requestId, user_id} = req.query;
const {lat, long, needId, user_id} = req.query;
const status = 'idle';
const latestMission = await getLatestMission(user_id);
const bids = (!hasStore() || !requestId) ? [] : await getBidsForRequest(requestId);
const bids = (!hasStore() || !needId) ? [] : await getBidsForNeed(needId);
let vehicles = [];
if (hasStore()) {
if (bids.length > 0) {
Expand All @@ -33,8 +33,8 @@ const getStatus = async (req, res) => {
await updateMission(latestMission.mission_id, {
'vehicle_signed_at': Date.now(),
'status': 'in_progress',
'vehicle_start_long': vehicle.long,
'vehicle_start_lat': vehicle.lat
'vehicle_start_longitude': vehicle.long,
'vehicle_start_latitude': vehicle.lat
});
await updateVehicleStatus(latestMission.vehicle_id, 'travelling_pickup');
await createMissionUpdate(latestMission.mission_id, 'travelling_pickup');
Expand Down
103 changes: 103 additions & 0 deletions server/controllers/constraints/need/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module.exports = {
pickup_at: {
numericality: {
greaterThanOrEqualTo: Date.now()
}
},
pickup_latitude: {
presence: true,
numericality: {
lessThanOrEqualTo: 90,
greaterThanOrEqualTo: -90
}
},
pickup_longitude: {
presence: true,
numericality: {
lessThanOrEqualTo: 180,
greaterThanOrEqualTo: -180
}
},
dropoff_latitude: {
presence: true,
numericality: {
lessThanOrEqualTo: 90,
greaterThanOrEqualTo: -90
}
},
dropoff_longitude: {
presence: true,
numericality: {
lessThanOrEqualTo: 180,
greaterThanOrEqualTo: -180
}
},
requester_name: {
length: {
minimum: 3,
}
},
requester_phone_number: {
length: {
minimum: 8,
}
},
cargo_type: {
presence: true,
numericality: {
onlyInteger: true,
strict: true,
lessThanOrEqualTo: 18,
greaterThanOrEqualTo: 1
}
},
hazardous_goods: {
numericality: {
onlyInteger: true,
strict: true,
lessThanOrEqualTo: 9,
greaterThanOrEqualTo: 1
}
},
ip_protection_level: {
numericality: {
onlyInteger: true,
strict: true,
lessThanOrEqualTo: 69,
greaterThanOrEqualTo: 54
}
},
height: {
numericality: {
greaterThan: 0
}
},
width: {
numericality: {
greaterThan: 0
}
},
length: {
numericality: {
greaterThan: 0
}
},
weight: {
numericality: {
greaterThan: 0
}
},
insurance_required: {
type: 'boolean'
},
insured_value: {
numericality: {
greaterThan: 0
}
},
insured_value_currency: {
length: {
is: 3
}
}
};
Loading

0 comments on commit 1c520cf

Please sign in to comment.