123456789101112131415161718192021222324252627282930313233343536 |
- '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 GroupService extends CrudService {
- constructor(ctx) {
- super(ctx, 'group');
- this.model = this.ctx.model.Group;
- }
- async insert(data) {
- const { groupid, studentid } = data;
- const group = await this.model.findById(groupid);
- if (group.studentid.includes(studentid)) {
- throw new BusinessError(ErrorCode.DATA_EXIST, '您已加入该组,请勿重复操作');
- } else {
- group.studentid.push(studentid);
- await group.save();
- }
- }
- async exit(data) {
- const { groupid, studentid } = data;
- const group = await this.model.findById(groupid);
- group.studentid.remove(studentid);
- await group.save();
- }
- }
- module.exports = GroupService;
|