phone
This commit is contained in:
@@ -3,7 +3,6 @@ import { Admin } from '../entities/admin.entity';
|
||||
import { Role } from '../../roles/entities/role.entity';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { UpdateAdminDto } from '../dto/update-admin.dto';
|
||||
import { normalizePhone } from '../../util/phone.util';
|
||||
import { CreateAdminDto } from '../dto/create-admin.dto';
|
||||
import { AdminRepository } from '../repositories/admin.repository';
|
||||
import { RoleRepository } from 'src/modules/roles/respository/role.repository';
|
||||
@@ -20,10 +19,9 @@ export class AdminService {
|
||||
async create(dto: CreateAdminDto) {
|
||||
const { phone, firstName, lastName, roleId } = dto;
|
||||
|
||||
const normalizedPhone = normalizePhone(phone);
|
||||
|
||||
const currentAdmin = await this.adminRepository.findOne({
|
||||
phone: normalizedPhone,
|
||||
phone,
|
||||
}, { filters: { notDeleted: false } });
|
||||
|
||||
if (currentAdmin && !currentAdmin.deletedAt) {
|
||||
@@ -42,7 +40,7 @@ export class AdminService {
|
||||
}
|
||||
|
||||
const admin = this.em.create(Admin, {
|
||||
phone: normalizedPhone,
|
||||
phone,
|
||||
firstName,
|
||||
lastName,
|
||||
role,
|
||||
@@ -52,8 +50,7 @@ export class AdminService {
|
||||
}
|
||||
|
||||
async findByPhone(phone: string): Promise<Admin | null> {
|
||||
const normalizedPhone = normalizePhone(phone);
|
||||
return this.adminRepository.findOne({ phone: normalizedPhone });
|
||||
return this.adminRepository.findOne({ phone });
|
||||
}
|
||||
|
||||
async findById(adminId: string): Promise<Admin | null> {
|
||||
@@ -89,12 +86,11 @@ export class AdminService {
|
||||
}
|
||||
|
||||
if (rest.phone !== undefined && rest.phone !== admin.phone) {
|
||||
const normalizedPhone = normalizePhone(rest.phone);
|
||||
const exists = await this.adminRepository.findOne({ phone: normalizedPhone });
|
||||
const exists = await this.adminRepository.findOne({ phone: rest.phone });
|
||||
if (exists) {
|
||||
throw new ConflictException('This Phone Number is already taken');
|
||||
}
|
||||
admin.phone = normalizedPhone;
|
||||
admin.phone = rest.phone;
|
||||
}
|
||||
|
||||
// Update role if roleId is provided
|
||||
|
||||
Reference in New Issue
Block a user