UpdateSelfAccount.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const API = require("../../../lib/API.js")
  2. const AccessControl = require("../../../lib/AccessControl.js")
  3. const { BaseStdResponse } = require("../../../BaseStdResponse.js")
  4. const { syncAccountInfo } = require("../../../lib/Lepao/syncAccountInfo")
  5. class UpdateSelfAccount extends API {
  6. constructor() {
  7. super()
  8. this.setPath('/Lepao/Account/UpdateSelfAccount')
  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. try {
  24. const syncResult = await syncAccountInfo({
  25. studentNum: student_num,
  26. createUser: uuid,
  27. logger: this.logger
  28. })
  29. if (!syncResult.ok) {
  30. return res.json({
  31. ...BaseStdResponse.ERR,
  32. msg: syncResult.msg || '同步失败,请稍后再试'
  33. })
  34. }
  35. return res.json({
  36. ...BaseStdResponse.OK,
  37. data: syncResult.data
  38. })
  39. } catch (error) {
  40. this.logger.error(`用户自助同步乐跑账号失败: ${error.stack || error}`)
  41. return res.json({
  42. ...BaseStdResponse.ERR,
  43. msg: '同步失败,请稍后再试'
  44. })
  45. }
  46. }
  47. }
  48. module.exports.UpdateSelfAccount = UpdateSelfAccount