|
@@ -1,8 +1,8 @@
|
|
|
'use strict';
|
|
|
|
|
|
-// const assert = require('assert');
|
|
|
-// const _ = require('lodash');
|
|
|
-// const { ObjectId } = require('mongoose').Types;
|
|
|
+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;
|
|
|
|
|
@@ -11,6 +11,28 @@ class PersonroomService extends CrudService {
|
|
|
super(ctx, 'personroom');
|
|
|
this.model = this.ctx.model.Personroom;
|
|
|
}
|
|
|
+
|
|
|
+ async create(query, { buyer_id, seller_id, buyer_name, seller_name }) {
|
|
|
+ assert(buyer_id, '缺少买家信息');
|
|
|
+ assert(seller_id, '缺少卖家信息');
|
|
|
+ assert(buyer_name, '缺少买家信息');
|
|
|
+ assert(seller_name, '缺少卖家信息');
|
|
|
+ const res = await this.model.create({ buyer_id, seller_id, buyer_name, seller_name });
|
|
|
+ // TODO MQ
|
|
|
+ const { mq } = this.ctx;
|
|
|
+ if (mq) {
|
|
|
+ const exchange = 'person_room';
|
|
|
+ const parm = {
|
|
|
+ durable: true,
|
|
|
+ headers: {
|
|
|
+ room_id: res.id,
|
|
|
+ buyer_id,
|
|
|
+ seller_id,
|
|
|
+ } };
|
|
|
+ mq.topic(exchange, seller_id, '您有买家进行对接请及时查收', parm);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = PersonroomService;
|