12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 'use strict';
- const assert = require('assert');
- const _ = require('lodash');
- const { ObjectId } = require('mongoose').Types;
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const moment = require('moment');
- class ChatService extends CrudService {
- constructor(ctx) {
- super(ctx, 'dock');
- this.model = this.ctx.model.Dock;
- }
- // async create(query, { sender_id, sender_name, content }) {
- // assert(sender_name, '缺少发言人信息');
- // assert(content, '缺少发言内容');
- // const send_time = moment().format('YYYY-MM-DD HH:mm:ss');
- // const res = await this.model.create({
- // sender_id,
- // sender_name,
- // content,
- // send_time,
- // });
- // return res;
- // }
- async apply({ id }, body) {
- const dock = await this.model.findOne({ _id: ObjectId(id) });
- if (!dock) {
- throw new BusinessError('没有查询到该对接会');
- }
- dock.apply.push({
- ...body,
- apply_time: moment().format('YYYY-MM-DD HH:mm:ss'),
- });
- const res = await dock.save();
- const info = _.last(res.apply);
- return info;
- }
- async check({ id, dock_id }, { status }) {
- assert(status, '请审核是否允许参加对接会');
- const dock = await this.model.findOne({ _id: ObjectId(dock_id) });
- if (!dock) {
- throw new BusinessError('没有查询到该对接会');
- }
- const user = dock.apply.id(id);
- if (!user) {
- throw new BusinessError('没有查询到用户的申请');
- }
- user.status = status;
- const res = dock.save();
- return res;
- }
- async dockCheck({ id }, { is_allowed, reason = '' }) {
- const dock = await this.model.findOne({ _id: ObjectId(id) });
- if (!dock) {
- throw new BusinessError('没有查询到该对接会');
- }
- assert(is_allowed, '请选择审核结果');
- dock.is_allowed = is_allowed;
- dock.reason = reason;
- const res = await dock.save();
- return res;
- }
- }
- module.exports = ChatService;
|