|
@@ -16,12 +16,41 @@ class HeadteacherService extends CrudService {
|
|
|
|
|
|
async create(data) {
|
|
|
const { name, phone } = data;
|
|
|
+ const user = await this.umodel.findOne({ mobile: phone });
|
|
|
+ if (user) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_EXIST, '电话已经存在');
|
|
|
+ }
|
|
|
const res = await this.model.create(data);
|
|
|
const newdata = { name, mobile: phone, type: '1', uid: res.id };
|
|
|
newdata.passwd = { secret: '12345678' };
|
|
|
await this.umodel.create(newdata);
|
|
|
}
|
|
|
|
|
|
+ async update({ id }, data) {
|
|
|
+ const { name, phone, openid } = data;
|
|
|
+ const user = await this.umodel.findOne({ mobile: phone });
|
|
|
+ const res = await this.model.update({ id }, data);
|
|
|
+ if (res) {
|
|
|
+ const _user = await this.umodel.findOne({ uid: id, thpe: '1' });
|
|
|
+ if (_user) {
|
|
|
+ _user.mobile = phone;
|
|
|
+ _user.name = name;
|
|
|
+ if (openid) {
|
|
|
+ _user.openid = openid;
|
|
|
+ }
|
|
|
+ user.save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ async delete({ id }) {
|
|
|
+ const res = await this.model.findByIdAndDelete(id);
|
|
|
+ const _user = await this.umodel.findOne({ uid: id, thpe: '1' });
|
|
|
+ _user.delete();
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
module.exports = HeadteacherService;
|