From 05e38c2e2d084b628a9edc7233c5e496d093da59 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 6 Apr 2017 18:17:26 +0800 Subject: [PATCH] update --- includes/language/zh.json | 2 ++ route/api/wristband.js | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/includes/language/zh.json b/includes/language/zh.json index ab828ea..6c51195 100644 --- a/includes/language/zh.json +++ b/includes/language/zh.json @@ -61,6 +61,8 @@ "ERR0059": "timezone設定失敗", "ERR0060": "手環ID輸入錯誤", "ERR0061": "手環ID已存在", + "ERR0062": "機器序號輸入錯誤", + "ERR0063": "機器序號已存在", "ERR7000": "命令執行失敗", diff --git a/route/api/wristband.js b/route/api/wristband.js index 1e96a91..f64ed6b 100644 --- a/route/api/wristband.js +++ b/route/api/wristband.js @@ -311,6 +311,18 @@ router .post('/addlocation', (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.sn) return n("ERR0062"); + if (!arr.data.name) return n('ERR0026'); + + let query = "select count(*) as c from ??.?? where `serialnumber` = ?"; + let param = [config.db.db9, 'location', arr.data.sn]; + + 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'); + }) }) .all('*', rt.send);