fix: UPDATE route route-count
This commit is contained in:
parent
c9f92d8885
commit
74c8bef18c
|
@ -1,19 +1,15 @@
|
|||
const debug=require('debug')('debug');
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const routeCount = require('../service/route-count');
|
||||
const utils=require('../utils');
|
||||
|
||||
router.get('/', async function(req, res, next) {
|
||||
debug('route-count start...');
|
||||
try {
|
||||
res.json(await routeCount.get(req.query.agencyid));
|
||||
} catch (err) {
|
||||
console.error(`Error while getting route count, msg: `, err.message);
|
||||
res.status(err.statusCode || 500).json(utils.MSGS.error);
|
||||
}
|
||||
debug('route-count done.');
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
@ -1,24 +1,13 @@
|
|||
const debug=require('debug')('debug');
|
||||
const db = require('./db');
|
||||
|
||||
require('dotenv').config();
|
||||
|
||||
async function get(agencyId = 0) {
|
||||
debug('route-count start...');
|
||||
debug('agencyId: '+agencyId);
|
||||
|
||||
const schema = process.env.DB_SCHEMA || 'schema';
|
||||
debug('agency-all schema: ' + schema );
|
||||
|
||||
const query=`SELECT routes.route_id FROM ` + schema + `.routes WHERE agency_id='${agencyId}';`
|
||||
debug('query: '+query);
|
||||
|
||||
const res = await db.query( query );
|
||||
const len = res.length
|
||||
debug('route-count len: ' + len );
|
||||
debug('route-count done.');
|
||||
return len;
|
||||
}
|
||||
const rsp = await db.query( query );
|
||||
return rsp.length;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
get
|
||||
|
|
Loading…
Reference in New Issue