|
@@ -9,16 +9,17 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
|
|
|
class RoomService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
- super(ctx, 'room');
|
|
|
+ super(ctx, "room");
|
|
|
this.model = this.ctx.model.Room;
|
|
|
this.rumodel = this.ctx.model.Roomuser;
|
|
|
+ this.lookmodel = this.ctx.model.Lookuser;
|
|
|
}
|
|
|
|
|
|
async create(data) {
|
|
|
const { name } = data;
|
|
|
const room_ = await this.model.findOne({ name });
|
|
|
if (room_) {
|
|
|
- throw new BusinessError('此房间已经存在,请重新输入');
|
|
|
+ throw new BusinessError("此房间已经存在,请重新输入");
|
|
|
}
|
|
|
const roomuser = await this.rumodel.findById(data.anchorid);
|
|
|
if (!roomuser) {
|
|
@@ -35,6 +36,21 @@ class RoomService extends CrudService {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
+ async query({ skip, limit, ...info }) {
|
|
|
+ const total = await this.model.count(info);
|
|
|
+ const rooms = await this.model
|
|
|
+ .find(info)
|
|
|
+ .skip(Number(skip))
|
|
|
+ .limit(Number(limit));
|
|
|
+ const data = [];
|
|
|
+ for (const _room of rooms) {
|
|
|
+ const room = _.cloneDeep(JSON.parse(JSON.stringify(_room)));
|
|
|
+ const number = await this.lookmodel.count({ roomid: room._id });
|
|
|
+ room.number = number;
|
|
|
+ data.push(room);
|
|
|
+ }
|
|
|
+ return { data, total };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = RoomService;
|