-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'parent/master'
- Loading branch information
Showing
16 changed files
with
1,500 additions
and
149 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const config = { | ||
requests_ttl: 43200, | ||
needs_ttl: 43200, | ||
bids_ttl: 3600, | ||
vehicles_ttl: 86400, | ||
}; | ||
|
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,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}; |
This file was deleted.
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,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 | ||
} | ||
} | ||
}; |
Oops, something went wrong.