|
@@ -14,23 +14,32 @@ class GroupService extends CrudService {
|
|
|
}
|
|
|
|
|
|
async insert(data) {
|
|
|
- const { groupid, studentid } = data;
|
|
|
+ const { groupid, stuid, stuname } = data;
|
|
|
const group = await this.model.findById(groupid);
|
|
|
- if (group.studentid.includes(studentid)) {
|
|
|
+ const stuids = [];
|
|
|
+ for (const student of group.students) {
|
|
|
+ stuids.push(student.stuid);
|
|
|
+ }
|
|
|
+ if (stuids.includes(stuid)) {
|
|
|
throw new BusinessError(ErrorCode.DATA_EXIST, '您已加入该组,请勿重复操作');
|
|
|
} else {
|
|
|
- group.studentid.push(studentid);
|
|
|
+ group.students.push({ stuid, stuname });
|
|
|
await group.save();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async exit(data) {
|
|
|
- const { groupid, studentid } = data;
|
|
|
+ const { groupid, stuid } = data;
|
|
|
const group = await this.model.findById(groupid);
|
|
|
- group.studentid.remove(studentid);
|
|
|
+ const students = group.students;
|
|
|
+ for (const student of students) {
|
|
|
+ if (student.stuid === stuid) {
|
|
|
+ students.remove(student);
|
|
|
+ }
|
|
|
+ }
|
|
|
await group.save();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+
|
|
|
module.exports = GroupService;
|