chatroom.js 888 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. class ChatroomService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'chatroom');
  10. this.model = this.ctx.model.Chatroom;
  11. }
  12. async create({ teacherid, teacher, studentid, student }) {
  13. assert(teacherid, '缺少教师id');
  14. assert(teacher, '缺少教师姓名');
  15. assert(studentid, '缺少学生id');
  16. assert(student, '缺少学生姓名');
  17. const res = await this.model.findOne({ teacherid, teacher, studentid, student });
  18. if (res) return res;
  19. const cres = await this.model.create({ teacherid, teacher, studentid, student });
  20. return cres;
  21. }
  22. }
  23. module.exports = ChatroomService;