add mysql error send to frontend

This commit is contained in:
Jay 2017-03-31 17:14:42 +08:00
parent c1b443b9d2
commit e529794956
12 changed files with 96 additions and 71 deletions

View File

@ -32,7 +32,18 @@ function send(req, res) {
}; };
} }
if('sys_err' in res) {
json.sys_err = res.sys_err
}
res.send(json); res.send(json);
} }
module.exports = { send: send }; const err = (res, err, n, code = null) => {
if(process.env.NODE_ENV != 'production') res.sys_err = 'toString' in err && typeof err.toString == 'function' ? err.toString() : err;
if(!code) return n();
return n(code);
}
module.exports = { send, err };

View File

@ -125,7 +125,7 @@ router
} }
return n(); return n();
}) })
.catch(e => n('ERR8000')); .catch(e => rt.err(res,e, n,'ERR8000'));
}) })
.post('/setdioinfo', (req,res,n) => { .post('/setdioinfo', (req,res,n) => {
if(!config.permission.dio) return n('ERR9000'); if(!config.permission.dio) return n('ERR9000');
@ -177,7 +177,7 @@ router
Promise.all([pdi, pdo]) Promise.all([pdi, pdo])
.then(r => n()) .then(r => n())
.catch(e => n('ERR8002')) .catch(e => rt.err(res,e,n,'ERR8002'))
}) })
.all('*', rt.send); .all('*', rt.send);

View File

@ -46,11 +46,15 @@ router.use((err, req, res, n) => {
if (lngs.length > 0) { if (lngs.length > 0) {
lng = lngs[0].substring(0, 2); lng = lngs[0].substring(0, 2);
} }
res.send({ let json = {
errorCode: (typeof err != 'string' ? err.toString() : err), errorCode: (typeof err != 'string' ? err.toString() : err),
message: errMng(err, lng), message: errMng(err, lng),
status: 0 status: 0
}); };
if('sys_err' in res && process.env.NODE_ENV != 'production') json.sys_err = res.sys_err;
res.send(json);
}) })
module.exports = router; module.exports = router;

View File

@ -37,7 +37,7 @@ router
} }
res.db.query(query + order, param, (err, row) => { res.db.query(query + order, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
let dos = []; let dos = [];
let les = []; let les = [];
@ -88,7 +88,7 @@ router
return n(); return n();
}) })
.catch(err => { .catch(err => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
}); });
}); });
}) })
@ -104,7 +104,7 @@ router
let param = [config.db.db1, 'iogroup', arr.data.name, arr.data.devs]; let param = [config.db.db1, 'iogroup', arr.data.name, arr.data.devs];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8001'); if (err) return rt.err(res,err,n,'ERR8001');
let data = {}; let data = {};
data.record = []; data.record = [];
@ -129,7 +129,7 @@ router
`iogroupuid` = ?"; `iogroupuid` = ?";
let param = [config.db.db1, 'iogroup', arr.data.name, arr.data.devs, arr.data.id]; let param = [config.db.db1, 'iogroup', arr.data.name, arr.data.devs, arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002'); if (err) return rt.err(res,err,n,'ERR8002');
let data = {}; let data = {};
data.record = []; data.record = [];
@ -147,7 +147,7 @@ router
let query = "delete from ??.?? where `iogroupuid` = ? "; let query = "delete from ??.?? where `iogroupuid` = ? ";
let param = [config.db.db1, 'iogroup', arr.data.id]; let param = [config.db.db1, 'iogroup', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8003'); if (err) return rt.err(res,err,n,'ERR8003');
let data = {}; let data = {};
data.record = []; data.record = [];

View File

@ -28,7 +28,7 @@ router
let query = "select * from ??.??"; let query = "select * from ??.??";
let param = [config.db.db1, 'ipcam']; let param = [config.db.db1, 'ipcam'];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if(err) return n('ERR8000'); if(err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row) record: tool.checkArray(row)
@ -50,13 +50,13 @@ router
let query = "select count(*) as c from ??.?? where `ip` = ?"; let query = "select count(*) as c from ??.?? where `ip` = ?";
let param = [config.db.db1, 'ipcam', arr.data.ip]; let param = [config.db.db1, 'ipcam', arr.data.ip];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if(err || row.length == 0) return n('ERR8000'); if(err || row.length == 0) return rt.err(res,err,n,'ERR8000');
if(row[0]['c'] > 0) return n('ERR0027'); if(row[0]['c'] > 0) return n('ERR0027');
let query = "insert into ??.?? (`name`, `ip`) values (?,?)"; let query = "insert into ??.?? (`name`, `ip`) values (?,?)";
let param = [config.db.db1, 'ipcam', arr.data.name, arr.data.ip]; let param = [config.db.db1, 'ipcam', arr.data.name, arr.data.ip];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if(err) return n('ERR8001'); if(err) return rt.err(res,err,n,'ERR8001');
res.api_res = { res.api_res = {
record: [] record: []
}; };
@ -74,7 +74,7 @@ router
let query = "delete from ??.?? where `uid` = ?"; let query = "delete from ??.?? where `uid` = ?";
let param = [config.db.db1, 'ipcam', arr.data.id]; let param = [config.db.db1, 'ipcam', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if(err) return n('ERR8003'); if(err) return rt.err(res,err,n,'ERR8003');
res.api_res = { res.api_res = {
record: [] record: []
}; };
@ -92,7 +92,7 @@ router
let query = "update ??.?? set `name` = ? where `uid` = ?"; let query = "update ??.?? set `name` = ? where `uid` = ?";
let param = [config.db.db1, 'ipcam', arr.data.name, arr.data.id]; let param = [config.db.db1, 'ipcam', arr.data.name, arr.data.id];
res.db.query(query, param, (err,row) => { res.db.query(query, param, (err,row) => {
if(err) return n('ERR8002'); if(err) return rt.err(res,err,n,'ERR8002');
res.api_res = { res.api_res = {
record: [] record: []
} }

View File

@ -51,7 +51,7 @@ router
let query = "select `leonename`, `leoneip`, `leonelistuid` from ??.?? where `temporary` = '1' "; let query = "select `leonename`, `leoneip`, `leonelistuid` from ??.?? where `temporary` = '1' ";
let param = [config.db.db1, 'leonelist']; let param = [config.db.db1, 'leonelist'];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
let data = {}; let data = {};
data.record = tool.checkArray(row); data.record = tool.checkArray(row);
@ -83,7 +83,7 @@ router
} }
let order = " order by `leonelistuid` desc "; let order = " order by `leonelistuid` desc ";
res.db.query(query + order, param, (err, row) => { res.db.query(query + order, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
tool.getLeoneRT(rts => { tool.getLeoneRT(rts => {
let data = {}; let data = {};
@ -107,19 +107,19 @@ router
let query = "select count(*) as num from ??.?? where `temporary` = '0' "; let query = "select count(*) as num from ??.?? where `temporary` = '0' ";
let param = [config.db.db1, 'leonelist']; let param = [config.db.db1, 'leonelist'];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
if (row[0].num >= config.leone_limit) return n('ERR0056'); if (row[0].num >= config.leone_limit) return n('ERR0056');
let query = "select count(*) from ??.?? where `leoneip` = ? "; let query = "select count(*) from ??.?? where `leoneip` = ? ";
let p = [...param, arr.data.ip]; let p = [...param, arr.data.ip];
res.db.query(query, p, (err, row) => { res.db.query(query, p, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
if (row[0].num > 0) return n('ERR0027'); if (row[0].num > 0) return n('ERR0027');
let query = "insert into ??.?? (`leoneip`,`leonename`,`leonepassword`,`leone_add_date`,`leone_modify_date`) values (?,?,?,unix_timestamp(),unix_timestamp())"; let query = "insert into ??.?? (`leoneip`,`leonename`,`leonepassword`,`leone_add_date`,`leone_modify_date`) values (?,?,?,unix_timestamp(),unix_timestamp())";
let p = [...param, arr.data.ip, arr.data.name, arr.data.password]; let p = [...param, arr.data.ip, arr.data.name, arr.data.password];
res.db.query(query, p, (err, row) => { res.db.query(query, p, (err, row) => {
if (err) return n('ERR8001'); if (err) return rt.err(res,err,n,'ERR8001');
let data = {}; let data = {};
data.record = []; data.record = [];
@ -139,7 +139,7 @@ router
let query = "delete from ??.?? where `leonelistuid` = ? "; let query = "delete from ??.?? where `leonelistuid` = ? ";
let param = [config.db.db1, 'leonelist', arr.data.id]; let param = [config.db.db1, 'leonelist', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8003'); if (err) return rt.err(res,err,n,'ERR8003');
let data = {}; let data = {};
data.record = []; data.record = [];
res.api_res = data; res.api_res = data;
@ -163,7 +163,7 @@ router
`leonelistuid` = ? "; `leonelistuid` = ? ";
let param = [config.db.db1, 'leonelist', arr.data.name, arr.data.password, arr.data.id]; let param = [config.db.db1, 'leonelist', arr.data.name, arr.data.password, arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002'); if (err) return rt.err(res,err,n,'ERR8002');
let data = {}; let data = {};
data.record = []; data.record = [];
@ -172,7 +172,7 @@ router
let query = "select * from ??.?? where `leonelistuid` = ? "; let query = "select * from ??.?? where `leonelistuid` = ? ";
let param = [config.db.db1, 'leonelist', arr.data.id]; let param = [config.db.db1, 'leonelist', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n(); if (err) return rt.err(res,err,n);
if (row.length == 0) return n(); if (row.length == 0) return n();
let { leoneip, leonename, leonepassword } = row[0]; let { leoneip, leonename, leonepassword } = row[0];
@ -207,12 +207,12 @@ router
let query = "select count(*) as num from ??.?? where `temporary` = '0' or `leonelistuid` in (?)"; let query = "select count(*) as num from ??.?? where `temporary` = '0' or `leonelistuid` in (?)";
let param = [config.db.db1, 'leonelist', ids]; let param = [config.db.db1, 'leonelist', ids];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
if (row[0].num >= config.leone_limit) return n('ERR0056'); if (row[0].num >= config.leone_limit) return n('ERR0056');
let query = "update ??.?? set `temporary` = '0', `leone_modify_date` = unix_timestamp() where `leonelistuid` in (?)"; let query = "update ??.?? set `temporary` = '0', `leone_modify_date` = unix_timestamp() where `leonelistuid` in (?)";
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002'); if (err) return rt.err(res,err,n,'ERR8002');
let data = {}; let data = {};
data.record = []; data.record = [];
res.api_res = data; res.api_res = data;

View File

@ -36,7 +36,7 @@ router
let param = [config.db.db8, 'jcioclnt', config.db.db8, 'jcioclnt', config.db.db8, 'jcioclnt']; let param = [config.db.db8, 'jcioclnt', config.db.db8, 'jcioclnt', config.db.db8, 'jcioclnt'];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row) record: tool.checkArray(row)
@ -63,7 +63,7 @@ router
let param = [config.db.db8, 'getLink', arr.data.id]; let param = [config.db.db8, 'getLink', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
let ids = row[0].ids; let ids = row[0].ids;
let id = ids.split(','); let id = ids.split(',');
@ -104,7 +104,7 @@ router
} }
return n(); return n();
}) })
.catch(err => n('ERR8000')); .catch(err => rt.err(res,err,n,'ERR8000'));
}); });
}) })
.post('/addlink', (req, res, n) => { .post('/addlink', (req, res, n) => {
@ -173,7 +173,7 @@ router
let param = [config.db.db8, 'jcioclnt', (arr.data.active == 1 ? 1 : 0), arr.data.action, id.substr(2)]; let param = [config.db.db8, 'jcioclnt', (arr.data.active == 1 ? 1 : 0), arr.data.action, id.substr(2)];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002'); if (err) return rt.err(res,err,n,'ERR8002');
res.api_res = { res.api_res = {
record: [] record: []
@ -197,7 +197,7 @@ router
let param = [config.db.db8, 'jcioclnt', arr.data.id]; let param = [config.db.db8, 'jcioclnt', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002'); if (err) return rt.err(res,err,n,'ERR8002');
res.api_res = { res.api_res = {
record: [] record: []
@ -218,7 +218,7 @@ router
let param = [config.db.db8, 'getLink', arr.data.id]; let param = [config.db.db8, 'getLink', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
let ids = row[0].ids; let ids = row[0].ids;
let id = ids.split(','); let id = ids.split(',');
id.splice(0, 1); id.splice(0, 1);
@ -227,6 +227,7 @@ router
if (t != '') return t; if (t != '') return t;
}); });
res.db.query(`use ${config.db.db8}`);
let query = "delete c,n from ??.?? n \ let query = "delete c,n from ??.?? n \
left join ??.?? c \ left join ??.?? c \
on \ on \
@ -242,7 +243,7 @@ router
n.`jcioclntuid` in (?)"; n.`jcioclntuid` in (?)";
let param = [config.db.db8, 'jcioclnt', config.db.db7, 'jcioclct', ida]; let param = [config.db.db8, 'jcioclnt', config.db.db7, 'jcioclct', ida];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8003'); if (err) return rt.err(res,err,n,'ERR8003');
res.api_res = { res.api_res = {
record: [] record: []

View File

@ -27,13 +27,13 @@ router
let query = "select count(*) as num from ??.??"; let query = "select count(*) as num from ??.??";
let param = [config.db.db2, 'jciocert']; let param = [config.db.db2, 'jciocert'];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if(err || row.length == 0) return n('ERR0023'); if(err || row.length == 0) return rt.err(res,err,n,'ERR0023');
let page = mysql.recordPage(row[0].num, p, per); let page = mysql.recordPage(row[0].num, p, per);
let query = "select * from ??.?? order by `ioeventtst` desc "; let query = "select * from ??.?? order by `ioeventtst` desc ";
let limit = ` limit ${page.rec_start} , ${per} `; let limit = ` limit ${page.rec_start} , ${per} `;
res.db.query(query + limit, param, (err, row) => { res.db.query(query + limit, param, (err, row) => {
if(err) return n('ERR8000'); if(err) return rt.err(res,err,n,'ERR8000');
let data = {}; let data = {};
data.page = page; data.page = page;
data.record = tool.checkArray(row); data.record = tool.checkArray(row);

View File

@ -27,7 +27,7 @@ router
let param = [config.db.db5, 'device']; let param = [config.db.db5, 'device'];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row) record: tool.checkArray(row)
@ -47,7 +47,7 @@ router
let param = [config.db.db5, 'device', arr.data.id]; let param = [config.db.db5, 'device', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row), record: tool.checkArray(row),
@ -80,7 +80,7 @@ router
} }
return n(); return n();
}) })
.catch(err => n('ERR8000')); .catch(err => rt.err(res,err,n,'ERR8000'));
}); });
}) })
.post('/getporttype', (req, res, n) => { .post('/getporttype', (req, res, n) => {
@ -90,7 +90,7 @@ router
let param = [config.db.db5, 'porttype']; let param = [config.db.db5, 'porttype'];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row) record: tool.checkArray(row)
}; };
@ -115,7 +115,7 @@ router
let param = [config.db.db5, 'device', arr.data.name, arr.data.node, type, u, u]; let param = [config.db.db5, 'device', arr.data.name, arr.data.node, type, u, u];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8001'); if (err) return rt.err(res,err,n,'ERR8001');
res.api_res = { res.api_res = {
record: [] record: []
@ -138,7 +138,7 @@ router
let query = "select count(*) as num from ??.?? where `node` = ? and `uid` != ?"; let query = "select count(*) as num from ??.?? where `node` = ? and `uid` != ?";
let param = [config.db.db5, 'device', arr.data.node, arr.data.id]; let param = [config.db.db5, 'device', arr.data.node, arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
if (row[0].num > 0) return n('ERR0047'); if (row[0].num > 0) return n('ERR0047');
let u = ''; let u = '';
@ -155,7 +155,7 @@ router
`uid` = ?"; `uid` = ?";
let param = [config.db.db5, 'device', arr.data.name, arr.data.node, type, u, arr.data.id]; let param = [config.db.db5, 'device', arr.data.name, arr.data.node, type, u, arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002'); if (err) return rt.err(res,err,n,'ERR8002');
let q = "delete from ??.?? where `node` in (?)"; let q = "delete from ??.?? where `node` in (?)";
let p = [config.db.db6, 'jcmbrt', [arr.data.node, arr.data.original_node]]; let p = [config.db.db6, 'jcmbrt', [arr.data.node, arr.data.original_node]];
@ -187,7 +187,7 @@ router
d.`uid` = ?"; d.`uid` = ?";
let param = [config.db.db5, 'device', config.db.db5, 'iolist', config.db.db5, 'aioset', config.db.db6, 'jcmbrt', arr.data.id]; let param = [config.db.db5, 'device', config.db.db5, 'iolist', config.db.db5, 'aioset', config.db.db6, 'jcmbrt', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8003'); if (err) return rt.err(res,err,n,'ERR8003');
res.api_res = { res.api_res = {
record: [] record: []
}; };
@ -218,7 +218,7 @@ router
let param = [config.db.db6, 'jcmbrt', config.db.db5, 'device', config.db.db5, 'iolist', arr.data.type, config.db.db5, 'aioset', arr.data.id, arr.data.type]; let param = [config.db.db6, 'jcmbrt', config.db.db5, 'device', config.db.db5, 'iolist', arr.data.type, config.db.db5, 'aioset', arr.data.id, arr.data.type];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row) record: tool.checkArray(row)
@ -235,7 +235,7 @@ router
let query = "select * from ??.?? where `uid` = ? "; let query = "select * from ??.?? where `uid` = ? ";
let param = [config.db.db5, 'iolist', arr.data.id]; let param = [config.db.db5, 'iolist', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row) record: tool.checkArray(row)
@ -263,14 +263,14 @@ router
and `addr` = ?"; and `addr` = ?";
let param = [config.db.db5, 'iolist', arr.data.id, arr.data.type, arr.data.addr]; let param = [config.db.db5, 'iolist', arr.data.id, arr.data.type, arr.data.addr];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
if (row[0].c > 0) return n('ERR0054'); if (row[0].c > 0) return n('ERR0054');
let query = "insert into ??.?? (`devuid`,`type`,`addr`,`num`,`datalen`,`ctime`,`mtime`) values (?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp())"; let query = "insert into ??.?? (`devuid`,`type`,`addr`,`num`,`datalen`,`ctime`,`mtime`) values (?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp())";
let param = [config.db.db5, 'iolist', arr.data.id, arr.data.type, arr.data.addr, arr.data.num, dlen]; let param = [config.db.db5, 'iolist', arr.data.id, arr.data.type, arr.data.addr, arr.data.num, dlen];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8001'); if (err) return rt.err(res,err,n,'ERR8001');
res.api_res = { res.api_res = {
record: [] record: []
@ -301,7 +301,7 @@ router
and i2.`uid` is not null "; and i2.`uid` is not null ";
let param = [config.db.db5, 'iolist', config.db.db5, 'iolist', arr.data.addr, arr.data.id, arr.data.id]; let param = [config.db.db5, 'iolist', config.db.db5, 'iolist', arr.data.addr, arr.data.id, arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
if (row[0].c > 0) return n('ERR0054'); if (row[0].c > 0) return n('ERR0054');
let q = "update ??.?? set \ let q = "update ??.?? set \
@ -313,7 +313,7 @@ router
`uid` = ?"; `uid` = ?";
let p = [config.db.db5, 'iolist', arr.data.addr, arr.data.num, dlen, arr.data.id]; let p = [config.db.db5, 'iolist', arr.data.addr, arr.data.num, dlen, arr.data.id];
res.db.query(q, p, (err, row) => { res.db.query(q, p, (err, row) => {
if (err) return n('ERR8002'); if (err) return rt.err(res,err,n,'ERR8002');
res.api_res = { res.api_res = {
record: [] record: []
@ -338,7 +338,7 @@ router
i.`uid` = ?"; i.`uid` = ?";
let param = [config.db.db5, 'iolist', config.db.db5, 'aioset', arr.data.id]; let param = [config.db.db5, 'iolist', config.db.db5, 'aioset', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8003'); if (err) return rt.err(res,err,n,'ERR8003');
res.api_res = { res.api_res = {
record: [] record: []
@ -359,7 +359,7 @@ router
i.`uid` = ?"; i.`uid` = ?";
let param = [config.db.db5, 'aioset', config.db.db5, 'iolist', arr.data.id]; let param = [config.db.db5, 'aioset', config.db.db5, 'iolist', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row) record: tool.checkArray(row)
@ -376,7 +376,7 @@ router
let query = "select * from ??.?? where `uid` = ?"; let query = "select * from ??.?? where `uid` = ?";
let param = [config.db.db5, 'aioset', arr.data.id]; let param = [config.db.db5, 'aioset', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row) record: tool.checkArray(row)
@ -394,7 +394,7 @@ router
let query = "delete from ??.?? where `uid` = ?"; let query = "delete from ??.?? where `uid` = ?";
let param = [config.db.db5, 'aioset', arr.data.id]; let param = [config.db.db5, 'aioset', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8003'); if (err) return rt.err(res,err,n,'ERR8003');
res.api_res = { res.api_res = {
record: [] record: []
}; };
@ -418,7 +418,7 @@ router
let query = "select count(*) as count from ??.?? where `iouid` = ? and `portnum` = ?"; let query = "select count(*) as count from ??.?? where `iouid` = ? and `portnum` = ?";
let param = [config.db.db5, 'aioset', arr.data.iouid, arr.data.portnum]; let param = [config.db.db5, 'aioset', arr.data.iouid, arr.data.portnum];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
if (row[0].count > 0) return n('ERR0054'); if (row[0].count > 0) return n('ERR0054');
@ -426,7 +426,7 @@ router
(?, ?, ?, ?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp())"; (?, ?, ?, ?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp())";
let p = [config.db.db5, 'aioset', arr.data.iouid, arr.data.name, arr.data.portnum, arr.data.type, arr.data.range_min, arr.data.range_max, arr.data.scale_min, arr.data.scale_max]; let p = [config.db.db5, 'aioset', arr.data.iouid, arr.data.name, arr.data.portnum, arr.data.type, arr.data.range_min, arr.data.range_max, arr.data.scale_min, arr.data.scale_max];
res.db.query(q, p, (err, row) => { res.db.query(q, p, (err, row) => {
if (err) return n('ERR8001'); if (err) return rt.err(res,err,n,'ERR8001');
res.api_res = { res.api_res = {
record: [] record: []
@ -458,7 +458,7 @@ router
and `uid` != ?"; and `uid` != ?";
let param = [config.db.db5, 'aioset', arr.data.iouid, arr.data.portnum, arr.data.id]; let param = [config.db.db5, 'aioset', arr.data.iouid, arr.data.portnum, arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err || row.length == 0) return n('ERR8000'); if (err || row.length == 0) return rt.err(res,err,n,'ERR8000');
if (row[0].length > 0) return n('ERR0054'); if (row[0].length > 0) return n('ERR0054');
let query = "update ??.?? set \ let query = "update ??.?? set \
@ -473,7 +473,7 @@ router
where `uid` = ?"; where `uid` = ?";
let param = [config.db.db5, 'aioset', arr.data.name, arr.data.portnum, arr.data.type, arr.data.range_min, arr.data.range_max, arr.data.scale_min, arr.data.scale_max, arr.data.id]; let param = [config.db.db5, 'aioset', arr.data.name, arr.data.portnum, arr.data.type, arr.data.range_min, arr.data.range_max, arr.data.scale_min, arr.data.scale_max, arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002'); if (err) return rt.err(res,err,n,'ERR8002');
res.api_res = { res.api_res = {
record: [] record: []
@ -532,7 +532,7 @@ router
let param = [config.db.db10, 'jcmbrt', config.db.db5, 'device', config.db.db5, 'iolist', config.db.db5, 'aioset', arr.data.ids, arr.data.stime, arr.data.etime]; let param = [config.db.db10, 'jcmbrt', config.db.db5, 'device', config.db.db5, 'iolist', config.db.db5, 'aioset', arr.data.ids, arr.data.stime, arr.data.etime];
res.db.query(query, param, (err,row) => { res.db.query(query, param, (err,row) => {
if(err) return n('ERR8000'); if(err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row) record: tool.checkArray(row)
} }

View File

@ -41,7 +41,7 @@ router
} }
res.db.query(query + order, param, (err, row) => { res.db.query(query + order, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row), record: tool.checkArray(row),
@ -106,7 +106,7 @@ router
return n(); return n();
}) })
.catch(err => { .catch(err => {
return n(); return rt.err(res,err,n);
}) })
}); });
}) })
@ -121,7 +121,7 @@ router
let param = [config.db.db1, 'ioschedulet', arr.data.id]; let param = [config.db.db1, 'ioschedulet', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8003'); if (err) return rt.err(res,err,n,'ERR8003');
res.api_res = { res.api_res = {
record: [] record: []
@ -142,7 +142,7 @@ router
let param = [config.db.db1, 'ioschedulet', arr.data.id]; let param = [config.db.db1, 'ioschedulet', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002'); if (err) return rt.err(res,err,n,'ERR8002');
res.api_res = { res.api_res = {
record: [] record: []
@ -198,7 +198,7 @@ router
let param = [config.db.db1, 'ioschedulet', arr.data.name, active, arr.data.devs, arr.data.action, arr.data.min, arr.data.hour, d, m, w]; let param = [config.db.db1, 'ioschedulet', arr.data.name, active, arr.data.devs, arr.data.action, arr.data.min, arr.data.hour, d, m, w];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8001'); if (err) return rt.err(res,err,n,'ERR8001');
res.api_res = { res.api_res = {
record: [] record: []
@ -257,7 +257,7 @@ router
let param = [config.db.db1, 'ioschedulet', arr.data.name, active, arr.data.devs, arr.data.action, arr.data.min, arr.data.hour, d, m, w, arr.data.id]; let param = [config.db.db1, 'ioschedulet', arr.data.name, active, arr.data.devs, arr.data.action, arr.data.min, arr.data.hour, d, m, w, arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002'); if (err) return rt.err(res,err,n,'ERR8002');
res.api_res = { res.api_res = {
record: [] record: []

View File

@ -112,7 +112,7 @@ router
let query = "select * from ??.?? where `account` = ? and `user_password` = ?"; let query = "select * from ??.?? where `account` = ? and `user_password` = ?";
res.db.query(query, [config.db.db1, 'userlist', arr.data.account, arr.data.password], (err, row) => { res.db.query(query, [config.db.db1, 'userlist', arr.data.account, arr.data.password], (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res, err, n, 'ERR8000');
if (row.length == 0) return n('ERR0019'); if (row.length == 0) return n('ERR0019');
delete row[0]['user_password']; delete row[0]['user_password'];
@ -170,7 +170,7 @@ router
} }
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR8000'); if (err) return rt.err(res, err, n, 'ERR8000');
for (var i in row) { for (var i in row) {
delete row[i]['user_password']; delete row[i]['user_password'];
@ -192,7 +192,7 @@ router
let query = "delete from ??.?? where `account` = ?"; let query = "delete from ??.?? where `account` = ?";
let param = [config.db.db1, 'userlist', arr.data.account]; let param = [config.db.db1, 'userlist', arr.data.account];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR0020'); if (err) return rt.err(res,err, n, 'ERR0020');
let data = {}; let data = {};
data.record = []; data.record = [];
@ -222,7 +222,7 @@ router
param.push(arr.data.account); param.push(arr.data.account);
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR0021'); if (err) return rt.err(res,err,n,'ERR0021');
let data = {}; let data = {};
data.record = []; data.record = [];
res.api_res = data; res.api_res = data;
@ -243,7 +243,7 @@ router
let param = [config.db.db1, 'userlist', arr.data.account, arr.data.password, w.toString(), r.toString()]; let param = [config.db.db1, 'userlist', arr.data.account, arr.data.password, w.toString(), r.toString()];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if (err) return n('ERR0022'); if (err) return rt.err(res,err,n,'ERR0022');
let data = {}; let data = {};
data.record = []; data.record = [];
@ -354,7 +354,7 @@ router
return n(); return n();
}) })
.catch(e => { .catch(e => {
return n(); return rt.err(res, e, n);
}); });
}) })
.post('/getselectlist', (req, res, n) => { .post('/getselectlist', (req, res, n) => {
@ -450,7 +450,16 @@ router
}) })
}) })
.post('/gettimezoneset', (req,res,n) => { .post('/gettimezoneset', (req,res,n) => {
let query = "select * from ??.?? where `type` = ? limit 1";
let param = [config.db.db1, 'system', 'timezone'];
res.db.query(query, param, (err, row) => {
if(err) return rt.err(res,err,n, 'ERR8000');
res.api_res = {
record: tool.checkArray(row)
}
return n();
});
}) })
.all('*', rt.send); .all('*', rt.send);

View File

@ -167,7 +167,7 @@ router
let param = [config.db.db9, 'wristband', config.db.db9, 'rawdata', config.db.db9, 'lastdata', config.db.db9, 'location', config.db.db9, 'location',]; let param = [config.db.db9, 'wristband', config.db.db9, 'rawdata', config.db.db9, 'lastdata', config.db.db9, 'location', config.db.db9, 'location',];
res.db.query(query, param, (err,row) => { res.db.query(query, param, (err,row) => {
if(err) return n('ERR8000'); if(err) return rt.err(res,err,n,'ERR8000');
res.api_res = { res.api_res = {
record: tool.checkArray(row) record: tool.checkArray(row)