12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const assert = require('assert');
- //
- class TeamApplyService extends CrudService {
- constructor(ctx) {
- super(ctx, 'teamapply');
- this.model = this.ctx.model.Race.TeamApply;
- this.matchSignModel = this.ctx.model.Race.MatchSign;
- }
- /**
- * 查询项目下可以组队的人
- * @param {Object} query 地址栏查询条件
- * @property {String} project_id 项目地址
- * @property {String} user_id 项目地址
- */
- async findPartner({ project_id, user_id }) {
- // 多层嵌套populate
- const conn = this.app.mongooseDB.get('base');
- const schema = _.get(this.ctx.model, 'Base.User.schema');
- const m = conn.model('User', schema);
- let list = await this.matchSignModel.find({ user_id: { $ne: user_id }, pay_status: '1', project_id }).populate({
- path: 'user_id',
- select: 'user_id',
- populate: { path: 'user_id', model: m, select: 'name' },
- });
- if (list.length > 0) {
- list = JSON.parse(JSON.stringify(list));
- list = list.map(i => {
- i.user_name = _.get(i, 'user_id.user_id.name');
- i.user_id = _.get(i, 'user_id._id');
- return i;
- });
- }
- return list;
- }
- }
- module.exports = TeamApplyService;
|