|
@@ -10,6 +10,20 @@ class AdminService extends CrudService {
|
|
|
super(ctx, 'admin');
|
|
|
this.model = this.ctx.model.User.Admin;
|
|
|
}
|
|
|
+
|
|
|
+ async beforeCreate(data) {
|
|
|
+ const { account } = data;
|
|
|
+ const num = await this.model.count({ account });
|
|
|
+ if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '该账号名已存在');
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ async beforeUpdate(filter, update) {
|
|
|
+ const { account } = update;
|
|
|
+ const id = _.get(filter, '_id', _.get(filter, 'id'));
|
|
|
+ const num = await this.model.count({ _id: { $ne: id }, account });
|
|
|
+ if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '该账号名已存在');
|
|
|
+ return { filter, update };
|
|
|
+ }
|
|
|
/**
|
|
|
* 登陆
|
|
|
* @param {Object} body 登陆参数
|