Skip to content
Snippets Groups Projects
Commit c9f5e4c2 authored by Daniel's avatar Daniel
Browse files

app/api: driver: Add endpoint

parent d7e158d6
Branches
No related merge requests found
/*
* Tugas Besar 3 WBD - AMEN
*/
'use strict'
const express = require('express')
const Hub = require('../model/Hub.js')
let app = express.Router()
let hub = new Hub()
app.get('/find', function (req, res) {
let location = req.query.location
res.json({
'driver_ids': hub.filter(location)
})
})
app.get('/:id', function (req, res) {
let id = req.params.id
if (hub.drivers[id]) {
res.json({})
} else {
res.status(404).json({ 'error': 'Driver is not found' })
}
})
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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment