feat(api): add route stops-de

This commit is contained in:
dancingCycle 2023-06-15 10:51:42 +02:00
parent a799efb675
commit 43a721a46f
5 changed files with 38 additions and 1 deletions

1
api/.gitignore vendored
View File

@ -1,4 +1,5 @@
# Other
*~
.env~
f
p

View File

@ -11,6 +11,7 @@ const EXPRESS = require("express");
const CORS = require("cors");
const ROOTROUTER = require('./route/root');
const STOPS_DE_ROUTER = require('./route/stops-de');
const STOPS_NOT_DHID_ROUTER = require('./route/stops-not-dhid');
const STOPS_COUNT_NOT_DHID_ROUTER = require('./route/stops-count-not-dhid');
const STOPS_COUNT_ZHV = require('./route/stops-count-zhv');
@ -49,6 +50,7 @@ APP.use(CORS({
//api enable/disable?
APP.use('/', ROOTROUTER);
APP.use('/stops-de',STOPS_DE_ROUTER);
APP.use('/stops-not-dhid',STOPS_NOT_DHID_ROUTER);
APP.use('/stops-count-not-dhid',STOPS_COUNT_NOT_DHID_ROUTER);
APP.use('/stops-count-zhv',STOPS_COUNT_ZHV);

16
api/src/route/stops-de.js Normal file
View File

@ -0,0 +1,16 @@
const EXPRESS = require('express');
const ROUTER = EXPRESS.Router();
const STOPS_DE_OSET_LIMIT = require('../service/stops-de-oset-limit');
const UTILS=require('../utils');
//GET listing
ROUTER.get('/', async function(req, res, next) {
try {
res.json(await STOPS_DE_OSET_LIMIT.get(req.query.oset, req.query.limit));
} catch (err) {
console.error(`Error while getting data with oset and limit `, err.message);
res.status(err.statusCode || 500).json(UTILS.MSGS.error);
}
});
module.exports = ROUTER;

View File

@ -0,0 +1,18 @@
const debug=require('debug')('debug');
const db = require('./db');
const helper = require('../helper');
async function get(oset = 1,limit = 100) {
debug('stops-de-oset-limit start...');
const offset = helper.getOffset(oset, limit);
const rows = await db.query(
`SELECT stop_id,stop_name,stop_desc,stop_lat,stop_lon,parent_station,location_type,level_id,platform_code FROM analysis.tbl_stops_de OFFSET $1 LIMIT $2;`,
[offset, limit]
);
const data = helper.emptyOrRows(rows);
debug('stops-de-oset-limit done.');
return data;
};
module.exports = {
get
};

View File

@ -6,7 +6,7 @@ async function get(oset = 1,limit = 100) {
debug('stops-not-dhid-oset-limit start...');
const offset = helper.getOffset(oset, limit);
const rows = await db.query(
`SELECT stop_id,stop_name,stop_desc,stop_lat,stop_lon,parent_station,location_type,level_id,platform_code FROM analysis.vw_stops_not_dhid OFFSET $1 LIMIT $2;`,
`SELECT stop_id,stop_name,stop_desc,stop_lat,stop_lon,parent_station,location_type,level_id,platform_code FROM analysis.tbl_stops_not_dhid OFFSET $1 LIMIT $2;`,
[offset, limit]
);
const data = helper.emptyOrRows(rows);