sign.service.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { Provide, Inject } from '@midwayjs/decorator';
  2. import { ServiceError } from 'free-midway-component';
  3. import { InjectEntityModel } from '@midwayjs/typegoose';
  4. import { ReturnModelType } from '@typegoose/typegoose';
  5. import { BaseService } from 'free-midway-component';
  6. import { Sign } from '../../entity/platform/sign.entity';
  7. import { Match } from '../../entity/platform/match.entity';
  8. import { get } from 'lodash';
  9. import { I18nService } from '../i18n.service';
  10. import { FrameErrorEnum } from '../../error/frame.error';
  11. type modelType = ReturnModelType<typeof Sign>;
  12. @Provide()
  13. export class SignService extends BaseService<modelType> {
  14. @InjectEntityModel(Sign)
  15. model: modelType;
  16. @InjectEntityModel(Match)
  17. mModel: ReturnModelType<typeof Match>;
  18. @Inject()
  19. i18n: I18nService;
  20. // 报名检查
  21. async createExamine(data) {
  22. const { user, match } = data;
  23. const result = await this.model.findOne({ user, match }).lean();
  24. if (result) throw new ServiceError(this.i18n.translateError(FrameErrorEnum.SERVICE_REPEAT), FrameErrorEnum.SERVICE_REPEAT);
  25. }
  26. // 列表
  27. async sign(query) {
  28. const { skip = 0, limit = 0, ...condition } = query;
  29. const list = await this.model.find(condition).skip(skip).limit(limit).lean();
  30. const data = [];
  31. for (const val of list) {
  32. if (get(val, 'match')) {
  33. // 查询需求发布者
  34. const matchInfo = await this.mModel.findById(val.match).lean();
  35. if (matchInfo) {
  36. data.push({
  37. _id: get(val, '_id'),
  38. match: get(val, 'match'),
  39. money: get(matchInfo, 'money'),
  40. match_name: get(matchInfo, 'name'),
  41. match_time: get(matchInfo, 'time'),
  42. organization: get(matchInfo, 'organization'),
  43. time: get(val, 'time'),
  44. status: get(matchInfo, 'match_status'),
  45. });
  46. }
  47. }
  48. }
  49. const total = await this.model.count(condition);
  50. return { data, total };
  51. }
  52. }