EndAhead.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const API = require("../../../lib/API");
  2. const AccessControl = require("../../../lib/AccessControl");
  3. const ic = require("../../../lib/IC/IC").IC;
  4. const { BaseStdResponse } = require("../../../BaseStdResponse");
  5. class EndAhead extends API {
  6. constructor() {
  7. super();
  8. this.setPath('/IC/Seat/EndAhead')
  9. this.setMethod('post')
  10. }
  11. async onRequest(req, res) {
  12. let { uuid, session, username, seatuuid } = req.body
  13. if ([uuid, session, username, seatuuid].some(value => value === '' || value === null || value === undefined))
  14. return res.json({
  15. ...BaseStdResponse.MISSING_PARAMETER
  16. })
  17. // 检查 session
  18. if (!await AccessControl.checkSession(uuid, session))
  19. return res.status(401).json({
  20. ...BaseStdResponse.ACCESS_DENIED
  21. })
  22. const password = await AccessControl.checkJwAccount(uuid, username)
  23. if(!password)
  24. res.json({
  25. ...BaseStdResponse.ERR,
  26. msg: '教务系统账号未绑定或未激活'
  27. })
  28. try {
  29. let cookie = await ic.getCookie(username, password)
  30. let resdata = await ic.endAhead(cookie, seatuuid)
  31. if (resdata.code === 300) {
  32. cookie = await ic.resetCookie(username, password)
  33. resdata = await ic.endAhead(cookie, seatuuid)
  34. }
  35. res.json({
  36. ...BaseStdResponse.OK,
  37. data: resdata.data
  38. })
  39. } catch (error) {
  40. res.json({
  41. ...BaseStdResponse.ERR,
  42. msg: error.message || '取消预约失败!请稍后再试'
  43. })
  44. }
  45. }
  46. }
  47. module.exports.EndAhead = EndAhead