'use strict'; const assert = require('assert'); // const _ = require('lodash'); // const { ObjectId } = require('mongoose').Types; const moment = require('moment'); const { CrudService } = require('naf-framework-mongoose/lib/service'); // const { BusinessError, ErrorCode } = require('naf-core').Error; class RoomchatService extends CrudService { constructor(ctx) { super(ctx, 'roomchat'); this.model = this.ctx.model.Roomchat; } async create(query, { number, sender_id, sender_name, content, role }) { assert(sender_name, '缺少发言人信息'); assert(content, '缺少发言内容'); assert(number, '缺少房间号'); const send_time = moment().format('YYYY-MM-DD HH:mm:ss'); const res = await this.model.create({ number, sender_id, sender_name, content, send_time, role }); // TODO MQ const { mq } = this.ctx; if (mq) { const exchange = 'room_chat'; const parm = { durable: true, headers: { number, } }; mq.fanout(exchange, number, JSON.stringify(res), parm); } return res; } } module.exports = RoomchatService;