UpdateAccountInfo.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const API = require("../../../../lib/API")
  2. const AccessControl = require("../../../../lib/AccessControl")
  3. const { BaseStdResponse } = require("../../../../BaseStdResponse")
  4. const { syncAccountInfo } = require("../../../../lib/Lepao/syncAccountInfo")
  5. class UpdateAccountInfo extends API {
  6. constructor() {
  7. super()
  8. this.setPath('/Admin/Lepao/Account/UpdateAccountInfo')
  9. this.setMethod('POST')
  10. }
  11. async onRequest(req, res) {
  12. const { uuid, session, student_num } = req.body
  13. if ([uuid, session, student_num].some(v => v === '' || v === null || v === undefined)) {
  14. return res.json({
  15. ...BaseStdResponse.MISSING_PARAMETER
  16. })
  17. }
  18. if (!await AccessControl.checkSession(uuid, session)) {
  19. return res.status(401).json({
  20. ...BaseStdResponse.ACCESS_DENIED
  21. })
  22. }
  23. if (!await AccessControl.canAccess(uuid, ['action.lepao.admin.updateAccount'])) {
  24. return res.json({
  25. ...BaseStdResponse.PERMISSION_DENIED
  26. })
  27. }
  28. try {
  29. const syncResult = await syncAccountInfo({
  30. studentNum: student_num,
  31. logger: this.logger
  32. })
  33. if (!syncResult.ok) {
  34. return res.json({
  35. ...BaseStdResponse.ERR,
  36. msg: syncResult.msg || '同步失败,请稍后再试'
  37. })
  38. }
  39. return res.json({
  40. ...BaseStdResponse.OK,
  41. data: syncResult.data
  42. })
  43. } catch (error) {
  44. this.logger.error(`管理员同步乐跑账号失败: ${error.stack || error}`)
  45. return res.json({
  46. ...BaseStdResponse.ERR,
  47. msg: '同步失败,请稍后再试'
  48. })
  49. }
  50. }
  51. }
  52. module.exports.UpdateAccountInfo = UpdateAccountInfo