const API = require("../../../lib/API.js") const AccessControl = require("../../../lib/AccessControl.js") const { BaseStdResponse } = require("../../../BaseStdResponse.js") const { syncAccountInfo } = require("../../../lib/Lepao/syncAccountInfo") class UpdateSelfAccount extends API { constructor() { super() this.setPath('/Lepao/Account/UpdateSelfAccount') this.setMethod('POST') } async onRequest(req, res) { const { uuid, session, student_num } = req.body if ([uuid, session, student_num].some(v => v === '' || v === null || v === undefined)) { return res.json({ ...BaseStdResponse.MISSING_PARAMETER }) } if (!await AccessControl.checkSession(uuid, session)) { return res.status(401).json({ ...BaseStdResponse.ACCESS_DENIED }) } try { const syncResult = await syncAccountInfo({ studentNum: student_num, createUser: uuid, logger: this.logger }) if (!syncResult.ok) { return res.json({ ...BaseStdResponse.ERR, msg: syncResult.msg || '同步失败,请稍后再试' }) } return res.json({ ...BaseStdResponse.OK, data: syncResult.data }) } catch (error) { this.logger.error(`用户自助同步乐跑账号失败: ${error.stack || error}`) return res.json({ ...BaseStdResponse.ERR, msg: '同步失败,请稍后再试' }) } } } module.exports.UpdateSelfAccount = UpdateSelfAccount