An error occurred while loading the file. Please try again.
-
Daniel authored56fc550e
Forked from
IF3110 / TugasBesar3_2017
46 commits ahead of the upstream repository.
driver.js 840 B
/*
* Tugas Besar 3 WBD - AMEN
*/
'use strict'
const express = require('express')
const hub = require('../model/hub.js')
let app = express.Router()
app.get('/find', function (req, res) {
let location = req.query.location
res.json({
'driver_ids': hub.filter(location)
})
})
app.post('/', async function (req, res) {
let id = req.body.driver_id
let locations = req.body.locations
try {
let userId = await hub.waitAsync(id, locations, function (reject) {
req.connection.on('close', () => reject(new Error('Aborted')))
})
res.json({
'user_id': userId
})
} catch (e) {
console.log(e)
}
})
app.post('/pick', function (req, res) {
let driverId = req.body.driver_id
let userId = req.body.user_id
res.json({
'result': hub.pick(driverId, userId)
})
})
module.exports = app