Initial commit
This commit is contained in:
parent
a13ceef804
commit
8641fc9723
19 changed files with 303532 additions and 0 deletions
34
middleware/Stations.js
Normal file
34
middleware/Stations.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
import models from "../models";
|
||||
|
||||
class Stations {
|
||||
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)]
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const skip = start || 0;
|
||||
const _limit = limit && limit <= 50 ? limit : 20;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
export default Stations;
|
Loading…
Add table
Add a link
Reference in a new issue