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