admin
This commit is contained in:
@@ -42,22 +42,18 @@ export class AdminController {
|
||||
|
||||
@Patch('admin/admins/:adminId')
|
||||
@ApiOperation({ summary: 'Update an admin' })
|
||||
@ApiParam({ name: 'adminId', description: 'Admin ID' })
|
||||
@ApiBody({ type: UpdateAdminDto })
|
||||
update(@Param('adminId') adminId: string, @Body() dto: UpdateAdminDto,): Promise<Admin> {
|
||||
return this.adminService.update(adminId, dto);
|
||||
}
|
||||
|
||||
@Get('admin/admins/:adminId')
|
||||
@ApiOperation({ summary: 'Get an admin by ID' })
|
||||
@ApiParam({ name: 'id', description: 'Admin ID' })
|
||||
getById(@Param('adminId') adminId: string,): Promise<Admin | null> {
|
||||
return this.adminService.findById(adminId,);
|
||||
}
|
||||
|
||||
@Delete('admin/admins/:adminId')
|
||||
@ApiOperation({ summary: 'Delete an admin by ID' })
|
||||
@ApiParam({ name: 'id', description: 'Admin ID' })
|
||||
deleteById(@Param('adminId') adminId: string,): Promise<void> {
|
||||
return this.adminService.softDelete(adminId,);
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ export class AdminService {
|
||||
|
||||
const currentAdmin = await this.adminRepository.findOne({
|
||||
phone: normalizedPhone,
|
||||
});
|
||||
}, { filters: { notDeleted: false } });
|
||||
|
||||
if (currentAdmin && !currentAdmin.deletedAt) {
|
||||
throw new BadRequestException('This phone number is already used');
|
||||
}
|
||||
|
||||
//TODO : test admins that were delted
|
||||
// re-register deleted admin
|
||||
|
||||
// retrieve deleted admin
|
||||
if (currentAdmin && currentAdmin.deletedAt) {
|
||||
currentAdmin.deletedAt = undefined
|
||||
await this.em.flush()
|
||||
@@ -74,7 +74,7 @@ export class AdminService {
|
||||
async findById(adminId: string): Promise<Admin | null> {
|
||||
const admin = await this.adminRepository.findOne(
|
||||
{ id: adminId },
|
||||
{ populate: ['role'] },
|
||||
{ populate: ['role', 'role.permissions'] },
|
||||
);
|
||||
return admin;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export class RolesService {
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
const where: FilterQuery<Role> = { isSystem: false };
|
||||
const where: FilterQuery<Role> = {};
|
||||
|
||||
const roles = await this.roleRepository.find(where, {
|
||||
orderBy: { createdAt: 'desc' },
|
||||
|
||||
@@ -3,7 +3,6 @@ export interface AdminData {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
roleName: string;
|
||||
restaurantSlug: string | null;
|
||||
}
|
||||
|
||||
export const adminsData: AdminData[] = [
|
||||
@@ -12,27 +11,27 @@ export const adminsData: AdminData[] = [
|
||||
firstName: 'مرتضی',
|
||||
lastName: 'مرتضایی',
|
||||
roleName: 'admin',
|
||||
restaurantSlug: 'boote',
|
||||
|
||||
},
|
||||
{
|
||||
phone: '09185290775',
|
||||
firstName: 'حمید',
|
||||
lastName: 'ضرقامی',
|
||||
roleName: 'admin',
|
||||
restaurantSlug: 'boote',
|
||||
|
||||
},
|
||||
{
|
||||
phone: '09129283395',
|
||||
firstName: 'مهرداد',
|
||||
lastName: 'مظفری',
|
||||
roleName: 'admin',
|
||||
restaurantSlug: 'boote',
|
||||
roleName: 'designer',
|
||||
|
||||
},
|
||||
{
|
||||
phone: '09184317567',
|
||||
firstName: 'ادمین',
|
||||
lastName: 'هنر',
|
||||
roleName: 'admin',
|
||||
restaurantSlug: 'boote',
|
||||
firstName: 'حسابداری',
|
||||
lastName: 'ح',
|
||||
roleName: 'accountant',
|
||||
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user