This commit is contained in:
2025-12-16 13:02:20 +03:30
parent eb47fd75ea
commit e7d6f7bbee
3 changed files with 39 additions and 30 deletions
+3
View File
@@ -5,5 +5,8 @@
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.fixAll.eslint": "explicit"
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
}
}
@@ -8,106 +8,108 @@ import { UpdateGroupDto } from '../dto/update-group.dto';
import {
ApiTags,
ApiOperation,
ApiCreatedResponse,
ApiOkResponse,
ApiNotFoundResponse,
ApiParam,
ApiBody,
ApiBearerAuth,
} from '@nestjs/swagger';
import { SuperAdminAuthGuard } from 'src/modules/auth/guards/superAdminAuth.guard';
import { UseGuards } from '@nestjs/common';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
@ApiTags('icons')
@Controller('admin/icons')
@UseGuards(SuperAdminAuthGuard)
@Controller()
@ApiBearerAuth()
export class IconsController {
constructor(
private readonly iconService: IconService,
private readonly groupService: GroupService,
) {}
) { }
// Icon endpoints
@Post()
@Get('super-admin/groups/icons')
@UseGuards(AdminAuthGuard)
@ApiOperation({ summary: 'Get all icons' })
findAllPublicIcons() {
return this.groupService.findAllPublic();
}
@Post('super-admin/icons')
@UseGuards(SuperAdminAuthGuard)
@ApiOperation({ summary: 'Create icon' })
@ApiCreatedResponse({ description: 'Icon created', type: CreateIconDto })
@ApiBody({ type: CreateIconDto })
createIcon(@Body() dto: CreateIconDto) {
return this.iconService.create(dto);
}
@Get()
@Get('super-admin/icons')
@UseGuards(SuperAdminAuthGuard)
@ApiOperation({ summary: 'Get all icons' })
@ApiOkResponse({ description: 'List of all icons' })
findAllIcons() {
return this.iconService.findAll();
}
@Get(':id')
@Get('super-admin/icons/:id')
@UseGuards(SuperAdminAuthGuard)
@ApiOperation({ summary: 'Get icon by id' })
@ApiOkResponse({ description: 'Icon detail', type: CreateIconDto })
@ApiNotFoundResponse({ description: 'Icon not found' })
@ApiParam({ name: 'id', required: true, type: String })
findOneIcon(@Param('id') id: string) {
return this.iconService.findOne(id);
}
@Patch(':id')
@Patch('super-admin/icons/:id')
@UseGuards(SuperAdminAuthGuard)
@ApiOperation({ summary: 'Update icon' })
@ApiParam({ name: 'id' })
@ApiBody({ type: UpdateIconDto })
@ApiOkResponse({ description: 'Updated icon', type: UpdateIconDto })
updateIcon(@Param('id') id: string, @Body() dto: UpdateIconDto) {
return this.iconService.update(id, dto);
}
@Delete(':id')
@Delete('super-admin/icons/:id')
@UseGuards(SuperAdminAuthGuard)
@ApiOperation({ summary: 'Delete icon' })
@ApiParam({ name: 'id' })
@ApiOkResponse({ description: 'Deleted' })
removeIcon(@Param('id') id: string) {
return this.iconService.remove(id);
}
// Group endpoints (must come before :id routes to avoid route conflicts)
@Post('groups')
@Post('super-admin/icons/groups')
@UseGuards(SuperAdminAuthGuard)
@ApiOperation({ summary: 'Create icon group' })
@ApiCreatedResponse({ description: 'Group created', type: CreateGroupDto })
@ApiBody({ type: CreateGroupDto })
createGroup(@Body() dto: CreateGroupDto) {
return this.groupService.create(dto);
}
@Get('groups')
@Get('super-admin/icons/groups')
@UseGuards(SuperAdminAuthGuard)
@ApiOperation({ summary: 'Get all icon groups' })
@ApiOkResponse({ description: 'List of all icon groups' })
findAllGroups() {
return this.groupService.findAll();
}
@Get('groups/:id')
@Get('super-admin/icons/groups/:id')
@UseGuards(SuperAdminAuthGuard)
@ApiOperation({ summary: 'Get icon group by id' })
@ApiOkResponse({ description: 'Group detail', type: CreateGroupDto })
@ApiNotFoundResponse({ description: 'Group not found' })
@ApiParam({ name: 'id', required: true, type: String })
findOneGroup(@Param('id') id: string) {
return this.groupService.findOne(id);
}
@Patch('groups/:id')
@Patch('super-admin/icons/groups/:id')
@UseGuards(SuperAdminAuthGuard)
@ApiOperation({ summary: 'Update icon group' })
@ApiParam({ name: 'id' })
@ApiBody({ type: UpdateGroupDto })
@ApiOkResponse({ description: 'Updated group', type: UpdateGroupDto })
updateGroup(@Param('id') id: string, @Body() dto: UpdateGroupDto) {
return this.groupService.update(id, dto);
}
@Delete('groups/:id')
@Delete('super-admin/icons/groups/:id')
@UseGuards(SuperAdminAuthGuard)
@ApiOperation({ summary: 'Delete icon group' })
@ApiParam({ name: 'id' })
@ApiOkResponse({ description: 'Deleted' })
removeGroup(@Param('id') id: string) {
return this.groupService.remove(id);
}
@@ -54,5 +54,9 @@ export class GroupService {
group.deletedAt = new Date();
await this.em.persistAndFlush(group);
}
findAllPublic(): Promise<Group[]> {
return this.groupRepository.find({ deletedAt: null }, { populate: ['icons'] });
}
}