budget_check.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = options => {
  10. /**
  11. * 标段校验 中间件
  12. * 1. 读取标段数据(包括属性)
  13. * 2. 检验用户是否可见标段(不校验具体权限)
  14. *
  15. * @param {function} next - 中间件继续执行的方法
  16. * @return {void}
  17. */
  18. return function* budgetCheck(next) {
  19. try {
  20. // 读取标段数据
  21. const id = parseInt(this.params.id);
  22. if (!id) throw '参数错误';
  23. this.budget = yield this.service.budget.getDataById(id);
  24. if (!this.budget) throw '项目不存在';
  25. const bp = yield this.service.budgetPermission.getBudgetUserPermission(id);
  26. if (!bp) throw '您无权查看该项目';
  27. this.budget.readOnly = bp.permission.indexOf(this.service.budgetPermission.PermissionConst.edit.value) < 0;
  28. yield next;
  29. } catch (err) {
  30. this.log(err);
  31. if (this.helper.isAjax(this.request)) {
  32. this.ajaxErrorBody(err, '概算投资项目未知错误');
  33. } else {
  34. this.postError(err, '概算投资项目未知错误');
  35. }
  36. }
  37. };
  38. };