wristband first
This commit is contained in:
+82
-4
@@ -247,9 +247,15 @@ router
|
||||
let notify = arr.data.notify || 0;
|
||||
let sw = arr.data.switch || 0;
|
||||
|
||||
let query = "insert into ??.?? (`mac`, `name`, `identity`, `monitor`, `notify`, `switch`, `ctime`, `mtime`) values \
|
||||
( ?, ?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp() )";
|
||||
let param = [config.db.db9, 'wristband', arr.data.mac, name, identity, monitor, notify, sw];
|
||||
let u = '';
|
||||
let obj = so.get(req.headers['x-auth-token']);
|
||||
if (obj != null && 'user' in obj && 'account' in obj.user) {
|
||||
u = obj.user.account;
|
||||
}
|
||||
|
||||
let query = "insert into ??.?? (`mac`, `name`, `identity`, `monitor`, `notify`, `switch`, `cuser`, `muser`, `ctime`, `mtime`) values \
|
||||
( ?, ?, ?, ?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp() )";
|
||||
let param = [config.db.db9, 'wristband', arr.data.mac, name, identity, monitor, notify, sw, u, u];
|
||||
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err) return rt.err(res, err, n, 'ERR8001');
|
||||
@@ -274,16 +280,23 @@ router
|
||||
let notify = arr.data.notify || 0;
|
||||
let sw = arr.data.switch || 0;
|
||||
|
||||
let u = '';
|
||||
let obj = so.get(req.headers['x-auth-token']);
|
||||
if (obj != null && 'user' in obj && 'account' in obj.user) {
|
||||
u = obj.user.account;
|
||||
}
|
||||
|
||||
let query = "update ??.?? set \
|
||||
`name` = ?, \
|
||||
`identity` = ?, \
|
||||
`monitor` = ?, \
|
||||
`notify` = ?, \
|
||||
`switch` = ?, \
|
||||
`muser` = ?, \
|
||||
`mtime` = unix_timestamp() \
|
||||
where \
|
||||
`uid` = ?";
|
||||
let param = [config.db.db9, 'wristband', name, identity, monitor, notify, sw, arr.data.id];
|
||||
let param = [config.db.db9, 'wristband', name, identity, monitor, notify, sw, u, arr.data.id];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err) return rt.err(res, err, n, 'ERR8002');
|
||||
|
||||
@@ -322,6 +335,71 @@ router
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err || row.length == 0) return rt.err(res, err, n, 'ERR8000');
|
||||
if (row[0].c > 0) return n('ERR0063');
|
||||
|
||||
let u = '';
|
||||
let obj = so.get(req.headers['x-auth-token']);
|
||||
if (obj != null && 'user' in obj && 'account' in obj.user) {
|
||||
u = obj.user.account;
|
||||
}
|
||||
|
||||
let query = "insert into ??.?? (`name`, `serialnumber`, `cuser`, `ctime`, `muser`, `mtime`) values (?, ?, ?, unix_timestamp(), ?, unix_timestamp())";
|
||||
let param = [config.db.db9, 'location', arr.data.name, arr.data.sn, u, u];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err) return rt.err(res, err, n, 'ERR8001');
|
||||
res.api_res = {
|
||||
record: []
|
||||
}
|
||||
n();
|
||||
});
|
||||
})
|
||||
})
|
||||
.post('/editlocation', (req, res, n) => {
|
||||
if (!config.permission.wristband) return n('ERR9000');
|
||||
if (!tool.checkPermission(req)) return n('ERR9000');
|
||||
let arr = req.body;
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
if (!arr.data.name) return n('ERR0026');
|
||||
|
||||
let u = '';
|
||||
let obj = so.get(req.headers['x-auth-token']);
|
||||
if (obj != null && 'user' in obj && 'account' in obj.user) {
|
||||
u = obj.user.account;
|
||||
}
|
||||
|
||||
let query = "update ??.?? set \
|
||||
`name` = ?, \
|
||||
`muser` = ?, \
|
||||
`mtime` = unix_timestamp() \
|
||||
where \
|
||||
`uid` = ? ";
|
||||
let param = [config.db.db9, 'location', arr.data.name, u, arr.data.id];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err) return rt.err(res, err, n, 'ERR8002');
|
||||
|
||||
res.api_res = {
|
||||
record: []
|
||||
};
|
||||
n();
|
||||
})
|
||||
})
|
||||
.post('/dellocation', (req, res, n) => {
|
||||
if (!config.permission.wristband) return n('ERR9000');
|
||||
if (!tool.checkPermission(req)) return n('ERR9000');
|
||||
let arr = req.body;
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db.query(`use ${config.db.db9}`);
|
||||
|
||||
let query = "delete from ??.?? where `uid` = ?";
|
||||
let param = [config.db.db9, 'location', arr.data.id];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err) return rt.err(res, err, n, 'ERR8003');
|
||||
res.api_res = {
|
||||
record: []
|
||||
}
|
||||
n();
|
||||
})
|
||||
})
|
||||
.all('*', rt.send);
|
||||
|
||||
Reference in New Issue
Block a user