dock.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. const moment = require('moment');
  8. class ChatService extends CrudService {
  9. constructor(ctx) {
  10. super(ctx, 'dock');
  11. this.model = this.ctx.model.Dock;
  12. }
  13. // async create(query, { sender_id, sender_name, content }) {
  14. // assert(sender_name, '缺少发言人信息');
  15. // assert(content, '缺少发言内容');
  16. // const send_time = moment().format('YYYY-MM-DD HH:mm:ss');
  17. // const res = await this.model.create({
  18. // sender_id,
  19. // sender_name,
  20. // content,
  21. // send_time,
  22. // });
  23. // return res;
  24. // }
  25. async apply({ id }, body) {
  26. const dock = await this.model.findOne({ _id: ObjectId(id) });
  27. if (!dock) {
  28. throw new BusinessError('没有查询到该对接会');
  29. }
  30. dock.apply.push({ ...body, apply_time: moment().format('YYYY-MM-DD HH:mm:ss') });
  31. const res = await dock.save();
  32. const info = _.last(res.apply);
  33. return info;
  34. }
  35. async check({ id, dock_id }, { status }) {
  36. assert(status, '请审核是否允许参加对接会');
  37. const dock = await this.model.findOne({ _id: ObjectId(dock_id) });
  38. if (!dock) {
  39. throw new BusinessError('没有查询到该对接会');
  40. }
  41. const user = dock.apply.id(id);
  42. if (!user) {
  43. throw new BusinessError('没有查询到用户的申请');
  44. }
  45. user.status = status;
  46. const res = dock.save();
  47. return res;
  48. }
  49. }
  50. module.exports = ChatService;