|
@@ -0,0 +1,54 @@
|
|
|
|
|
+const API = require("../../lib/API.js");
|
|
|
|
|
+const db = require("../../plugin/DataBase/db.js");
|
|
|
|
|
+const { BaseStdResponse } = require("../../BaseStdResponse.js");
|
|
|
|
|
+const AccessControl = require("../../lib/AccessControl");
|
|
|
|
|
+
|
|
|
|
|
+class GetType extends API {
|
|
|
|
|
+ constructor() {
|
|
|
|
|
+ super();
|
|
|
|
|
+
|
|
|
|
|
+ this.setPath('/Lepao/Account')
|
|
|
|
|
+ this.setMethod('POST')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async onRequest(req, res) {
|
|
|
|
|
+ let { uuid, session, student_num } = req.body
|
|
|
|
|
+
|
|
|
|
|
+ if ([uuid, session, student_num].some(value => value === '' || value === null || value === undefined))
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ ...BaseStdResponse.MISSING_PARAMETER,
|
|
|
|
|
+ endpoint: 1513126
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ if (!await AccessControl.checkSession(uuid, session))
|
|
|
|
|
+ return res.status(401).json({
|
|
|
|
|
+ ...BaseStdResponse.ACCESS_DENIED
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const time = new Date().getTime()
|
|
|
|
|
+
|
|
|
|
|
+ let sql, r
|
|
|
|
|
+
|
|
|
|
|
+ sql = 'INSERT INTO lepao_account (student_num, create_user, create_time) VALUES (?, ?, ?, ?)'
|
|
|
|
|
+ r = await db.query(sql, [student_num, uuid, time])
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (r && r.affectedRows > 0) {
|
|
|
|
|
+ res.json({
|
|
|
|
|
+ ...BaseStdResponse.OK,
|
|
|
|
|
+ id: r.insertId
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ res.json({ ...BaseStdResponse.ERR, endpoint: 7894378, msg: '添加乐跑账号失败!数据库错误' })
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ this.logger.error(`添加乐跑账号失败!${err.stack}`)
|
|
|
|
|
+ res.json({
|
|
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
|
|
+ msg: "添加乐跑账号失败!",
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+module.exports.GetType = GetType;
|