118 lines
2.9 KiB
TypeScript
118 lines
2.9 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { MenuService } from './menu.service';
|
|
import {
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiBearerAuth,
|
|
ApiQuery,
|
|
} from '@nestjs/swagger';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { RolesGuard } from '../common/guards/roles.guard';
|
|
import { Roles } from '../common/decorators/roles.decorator';
|
|
|
|
@ApiTags('Menu - مدیریت منو')
|
|
@Controller('menu')
|
|
export class MenuController {
|
|
constructor(private readonly menuService: MenuService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'دریافت منو عمومی بر اساس نوع' })
|
|
@ApiQuery({
|
|
name: 'type',
|
|
required: true,
|
|
description: 'HEADER | FOOTER_COL1 | FOOTER_COL2 | FOOTER_COL3',
|
|
})
|
|
findByType(@Query('type') type: string) {
|
|
return this.menuService.findByType(type);
|
|
}
|
|
|
|
@Get('type/:type')
|
|
@ApiOperation({ summary: 'دریافت منو عمومی با پارامتر مسیر' })
|
|
findByTypeParam(@Param('type') type: string) {
|
|
return this.menuService.findByType(type);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Get('admin')
|
|
@ApiOperation({ summary: 'دریافت تمام آیتمهای منو (ادمین)' })
|
|
@ApiQuery({ name: 'type', required: false })
|
|
findAllAdmin(@Query('type') type?: string) {
|
|
return this.menuService.findAllAdmin(type);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Post()
|
|
@ApiOperation({ summary: 'ایجاد آیتم منو جدید' })
|
|
create(
|
|
@Body()
|
|
body: {
|
|
menuType: string;
|
|
label: string;
|
|
href: string;
|
|
parentId?: string;
|
|
order?: number;
|
|
isActive?: boolean;
|
|
isExternal?: boolean;
|
|
icon?: string;
|
|
badge?: string;
|
|
},
|
|
) {
|
|
return this.menuService.create(body);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Put('reorder')
|
|
@ApiOperation({ summary: 'مرتبسازی آیتمهای منو' })
|
|
reorder(@Body() body: { items: { id: string; order: number }[] }) {
|
|
return this.menuService.reorder(body.items);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Put(':id')
|
|
@ApiOperation({ summary: 'ویرایش آیتم منو' })
|
|
update(
|
|
@Param('id') id: string,
|
|
@Body()
|
|
body: Partial<{
|
|
menuType: string;
|
|
label: string;
|
|
href: string;
|
|
parentId: string | null;
|
|
order: number;
|
|
isActive: boolean;
|
|
isExternal: boolean;
|
|
icon: string;
|
|
badge: string;
|
|
}>,
|
|
) {
|
|
return this.menuService.update(id, body);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@ApiBearerAuth()
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: 'حذف آیتم منو' })
|
|
remove(@Param('id') id: string) {
|
|
return this.menuService.remove(id);
|
|
}
|
|
}
|