|
@@ -18,11 +18,27 @@ export class UserService extends BaseServiceV2 {
|
|
|
else data.status = '1';
|
|
|
return data;
|
|
|
}
|
|
|
+ async checkEmail(data) {
|
|
|
+ const email = get(data, 'email');
|
|
|
+ if (!email) return;
|
|
|
+ const builder = await this.model.createQueryBuilder().where('"email" =:value', { value: email });
|
|
|
+ // 如果有id,则视为修改,查非自己的email是否存在
|
|
|
+ const id = get(data, 'id');
|
|
|
+ if (id) builder.andWhere('"id" != :id', { id });
|
|
|
+ const num = await builder.getCount();
|
|
|
+ if (num <= 0) return true;
|
|
|
+ // 邮箱存在
|
|
|
+ throw new ServiceError(ErrorCode.EMAIL_IS_EXISTS);
|
|
|
+ }
|
|
|
|
|
|
async checkPhone(data) {
|
|
|
const phone = get(data, 'phone');
|
|
|
if (!phone) return;
|
|
|
- const num = await this.model.createQueryBuilder().where('"phone" =:value', { value: phone }).getCount();
|
|
|
+ const builder = await this.model.createQueryBuilder().where('"phone" =:value', { value: phone });
|
|
|
+ // 如果有id,则视为修改,查非自己的phone是否存在
|
|
|
+ const id = get(data, 'id');
|
|
|
+ if (id) builder.andWhere('"id" != :id', { id });
|
|
|
+ const num = await builder.getCount();
|
|
|
if (num <= 0) return true;
|
|
|
// 手机号存在
|
|
|
throw new ServiceError(ErrorCode.PHONE_IS_EXISTS);
|