Added name of stations

This commit is contained in:
Damien Broqua 2020-03-06 15:49:16 +01:00
parent 4db191ca0f
commit 3e38fc79b9
6 changed files with 394 additions and 54 deletions

View file

@ -1,33 +1,43 @@
import models from "../models";
class Stations {
/**
* Méthode permettant de récuper la liste des stations selon des critères
* @param {Object} req
* @param {Function} callback
*/
static getAll(req, callback) {
const { radius, lon, lat, start, limit } = req.query;
const query = {
location: {
$near: {
$maxDistance: Number(radius),
$geometry: {
type: "Point",
coordinates: [Number(lon), Number(lat)]
if (!lon || !lat) {
callback(new Error("Missing lat, lon or radius"));
} else {
const query = {
location: {
$near: {
$maxDistance: Number(radius),
$geometry: {
type: "Point",
coordinates: [Number(lon), Number(lat)]
}
}
}
}
};
};
const skip = start || 0;
const _limit = limit && limit <= 50 ? limit : 20;
const skip = parseInt(start || 0, 10);
const _limit = parseInt(limit && limit <= 50 ? limit : 20, 10);
models.Stations.count(query)
.then(count => {
models.Stations.find(query)
.skip(parseInt(skip, 10))
.limit(parseInt(_limit, 10))
.then(items => {
callback(null, { total: count, items });
});
})
.catch(callback);
models.Stations.count(query)
.then(count => {
models.Stations.find(query)
.skip(skip)
.limit(_limit)
.then(items => {
callback(null, { total: count, items });
});
})
.catch(callback);
}
}
}