|
@@ -16,6 +16,7 @@ class LeaveService extends CrudService {
|
|
|
this.cmodel = this.ctx.model.Class;
|
|
|
}
|
|
|
async create(data) {
|
|
|
+ const { type } = data;
|
|
|
const studentid = data.studentid;
|
|
|
const student = await this.smodel.findById(studentid);
|
|
|
const schid = student.schid;
|
|
@@ -25,7 +26,22 @@ class LeaveService extends CrudService {
|
|
|
sch = JSON.parse(JSON.stringify(sch));
|
|
|
const { _id } = sch;
|
|
|
const user = await this.umodel.findOne({ uid: _id, type: '2' });
|
|
|
- const entity = await this.model.create(newdata);
|
|
|
+ let entity;
|
|
|
+ if (type === '1') {
|
|
|
+ // 退出只能有一个
|
|
|
+ entity = await this.model.findOne({ studentid, type: '1' });
|
|
|
+ if (entity) {
|
|
|
+ const { starttime, endtime, reason } = data;
|
|
|
+ if (starttime) entity.starttime = starttime;
|
|
|
+ if (endtime) entity.endtime = endtime;
|
|
|
+ if (reason) entity.reason = reason;
|
|
|
+ await entity.save();
|
|
|
+ } else {
|
|
|
+ entity = await this.model.create(newdata);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ entity = await this.model.create(newdata);
|
|
|
+ }
|
|
|
if (user) {
|
|
|
const openid = user.openid;
|
|
|
const date = await this.ctx.service.util.updatedate();
|