1234567891011121314151617181920212223242526272829 |
- '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 ChatroomService extends CrudService {
- constructor(ctx) {
- super(ctx, 'chatroom');
- this.model = this.ctx.model.Chatroom;
- }
- async create({ teacherid, teacher, studentid, student }) {
- assert(teacherid, '缺少教师id');
- assert(teacher, '缺少教师姓名');
- assert(studentid, '缺少学生id');
- assert(student, '缺少学生姓名');
- const res = await this.model.findOne({ teacherid, teacher, studentid, student });
- if (res) return res;
- const cres = await this.model.create({ teacherid, teacher, studentid, student });
- return cres;
- }
- }
- module.exports = ChatroomService;
|