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