update seeder

This commit is contained in:
2026-02-05 11:02:28 +03:30
parent 068286e505
commit 38c64c4caa
11 changed files with 114 additions and 137 deletions
+14 -6
View File
@@ -23,13 +23,22 @@ export class AdminService {
const normalizedPhone = normalizePhone(phone);
const exist = await this.adminRepository.findOne({
const currentAdmin = await this.adminRepository.findOne({
phone: normalizedPhone,
});
if (exist) {
if (currentAdmin && !currentAdmin.deletedAt) {
throw new BadRequestException('This phone number is already used');
}
//TODO : test admins that were delted
// re-register deleted admin
if (currentAdmin && currentAdmin.deletedAt) {
currentAdmin.deletedAt = undefined
await this.em.flush()
return currentAdmin
}
const role = await this.roleRepository.findOne({ id: roleId })
if (!role) {
throw new BadRequestException('Role not found');
@@ -127,14 +136,13 @@ export class AdminService {
return admin;
}
async remove(adminId: string): Promise<void> {
async softDelete(adminId: string): Promise<void> {
const admin = await this.adminRepository.findOne({ id: adminId });
if (!admin) {
throw new NotFoundException('Admin role not found');
}
// admin.deletedAt=new Date()
// TODO :L is this correct to soft delete
return this.em.removeAndFlush(admin);
admin.deletedAt = new Date()
return this.em.flush();
}
async findOrFail(adminId: string) {