update seeder
This commit is contained in:
@@ -59,7 +59,7 @@ export class AdminController {
|
||||
@ApiOperation({ summary: 'Delete an admin by ID' })
|
||||
@ApiParam({ name: 'id', description: 'Admin ID' })
|
||||
deleteById(@Param('adminId') adminId: string,): Promise<void> {
|
||||
return this.adminService.remove(adminId,);
|
||||
return this.adminService.softDelete(adminId,);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user