matchExt.service.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { Inject, Provide } from '@midwayjs/core';
  2. import { InjectEntityModel } from '@midwayjs/typeorm';
  3. import { Repository } from 'typeorm';
  4. import { BaseServiceV2 } from '../../frame/BaseServiceV2';
  5. import { MatchExt } from '../../entity/match/matchExt.entity';
  6. import { UserService } from '../system/user.service';
  7. import { get, pick } from 'lodash';
  8. import { MatchService } from '../platform/match.service';
  9. import { MatchRegistrationService } from './matchRegistration.service';
  10. import { ErrorCode, ServiceError } from '../../error/service.error';
  11. @Provide()
  12. export class MatchExtService extends BaseServiceV2 {
  13. @InjectEntityModel(MatchExt)
  14. model: Repository<MatchExt>;
  15. @Inject()
  16. matchService: MatchService;
  17. @Inject()
  18. matchRegService: MatchRegistrationService;
  19. @Inject()
  20. userService: UserService;
  21. /**获取用户信息的属性 */
  22. async getUserProps(id, props) {
  23. if (!props) return;
  24. const user = await this.userService.fetch({ id });
  25. if (!user) return;
  26. const obj = pick(user, props);
  27. return obj;
  28. }
  29. /**
  30. * 赛事状态检查
  31. * @param id 赛事id
  32. * @param status 赛事应处于的状态码
  33. */
  34. async checkMatchStatus(id, status) {
  35. const data = await this.matchService.fetch({ id });
  36. if (!data) {
  37. throw new ServiceError(ErrorCode.MATCH_NOT_FOUND);
  38. }
  39. const data_status = get(data, 'status');
  40. if (status !== data_status) {
  41. // 抛出异常: 赛事状态不符合要求.
  42. throw new ServiceError(ErrorCode.MATCH_STATUS_ERROR);
  43. }
  44. return true;
  45. }
  46. /**
  47. * 赛事拓展状态检查
  48. * @param match_id 赛事拓展id
  49. * @param status 赛事拓展应处于的状态码
  50. */
  51. async checkMatchExtStatus(match_id, status) {
  52. const data = await this.fetch({ match_id });
  53. if (!data) {
  54. throw new ServiceError(ErrorCode.MATCH_NOT_FOUND);
  55. }
  56. const data_status = get(data, 'status');
  57. if (status !== data_status) {
  58. // 抛出异常: 赛事拓展状态不符合要求.
  59. throw new ServiceError(ErrorCode.MATCH_EXT_STATUS_ERROR);
  60. }
  61. return true;
  62. }
  63. /**
  64. * 赛事报名人员状态检查
  65. * @param id 赛事报名id
  66. * @param status 赛事报名应处于的状态码
  67. */
  68. async checkMatchRegStatus(id, status) {
  69. const data = await this.matchRegService.fetch({ id });
  70. if (!data) {
  71. throw new ServiceError(ErrorCode.MATCH_REG_NOT_FOUND);
  72. }
  73. const data_status = get(data, 'status');
  74. if (status !== data_status) {
  75. // 抛出异常: 赛事报名状态不符合要求.
  76. throw new ServiceError(ErrorCode.MATCH_REG_STATUS_ERROR);
  77. }
  78. return true;
  79. }
  80. }