12345678910111213141516171819202122232425262728293031323334 |
- '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;
- class RoomService extends CrudService {
- constructor(ctx) {
- super(ctx, 'room');
- this.model = this.ctx.model.Room;
- this.rumodel = this.ctx.model.Roomuser;
- }
- async create(data) {
- const { name } = data;
- const room_ = await this.model.findOne({ name });
- if (room_) {
- throw new BusinessError('此房间已经存在,请重新输入');
- }
- const roomuser = await this.rumodel.findById(data.anchorid);
- if (!roomuser) {
- throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
- }
- data.username = roomuser.name;
- const res = await this.model.create(data);
- return res;
- }
- }
- module.exports = RoomService;
|