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

ChatService: Add API to check active drivers

parent 2d5901f1
Branches
No related merge requests found
......@@ -63,7 +63,7 @@ let converse = function ($http) {
class Driver extends Account {
async waitAsync (timeout) {
let response = await $http.post(`${apiUrl}/driver/${this.id}/wait`, '', {
timeout: timeout
timeout: timeout.promise
})
return response.data.user_id
......@@ -71,13 +71,13 @@ let converse = function ($http) {
}
class User extends Account {
async checkAsync (id) {
try {
await $http.get(`${apiUrl}/driver/${id}`)
return true
} catch (e) {
return false
}
async checkAsync (ids) {
let data = JSON.stringify({
'driver_ids': ids
})
let response = await $http.post(`${apiUrl}/driver/check`, data)
return response.data.driver_ids
}
pickAsync (id) {
......
......@@ -46,14 +46,13 @@ app.post('/:id/pick', function (req, res) {
// Queries.
// <root>/driver/<id>
app.get('/:id', function (req, res) {
let id = Number(req.params.id)
// Check if driver exists.
hub.check(id)
// <root>/driver/check
app.post('/check', function (req, res) {
let driverIds = req.body.driver_ids
res.json({})
res.json({
driver_ids: hub.check(driverIds)
})
})
module.exports = app
......@@ -27,12 +27,8 @@ module.exports = {
}
},
check (id) {
let handle = drivers[id]
if (!handle) {
throw new Error(`Driver ID ${id} is not connected`)
}
check (ids) {
return ids.filter(id => drivers.hasOwnProperty(id))
},
pick (id, userId) {
......
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