1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { Provide, Inject } from '@midwayjs/decorator';
- import { ServiceError } from 'free-midway-component';
- import { InjectEntityModel } from '@midwayjs/typegoose';
- import { ReturnModelType } from '@typegoose/typegoose';
- import { BaseService } from 'free-midway-component';
- import { Sign } from '../../entity/platform/sign.entity';
- import { Match } from '../../entity/platform/match.entity';
- import { get } from 'lodash';
- import { I18nService } from '../i18n.service';
- import { FrameErrorEnum } from '../../error/frame.error';
- type modelType = ReturnModelType<typeof Sign>;
- @Provide()
- export class SignService extends BaseService<modelType> {
- @InjectEntityModel(Sign)
- model: modelType;
- @InjectEntityModel(Match)
- mModel: ReturnModelType<typeof Match>;
- @Inject()
- i18n: I18nService;
- // 报名检查
- async createExamine(data) {
- const { user, match } = data;
- const result = await this.model.findOne({ user, match }).lean();
- if (result) throw new ServiceError(this.i18n.translateError(FrameErrorEnum.SERVICE_REPEAT), FrameErrorEnum.SERVICE_REPEAT);
- }
- // 列表
- async sign(query) {
- const { skip = 0, limit = 0, ...condition } = query;
- const list = await this.model.find(condition).skip(skip).limit(limit).lean();
- const data = [];
- for (const val of list) {
- if (get(val, 'match')) {
- // 查询需求发布者
- const matchInfo = await this.mModel.findById(val.match).lean();
- if (matchInfo) {
- data.push({
- _id: get(val, '_id'),
- match: get(val, 'match'),
- money: get(matchInfo, 'money'),
- match_name: get(matchInfo, 'name'),
- match_time: get(matchInfo, 'time'),
- organization: get(matchInfo, 'organization'),
- time: get(val, 'time'),
- status: get(matchInfo, 'match_status'),
- });
- }
- }
- }
- const total = await this.model.count(condition);
- return { data, total };
- }
- }
|