127 lines
4.2 KiB
TypeScript
127 lines
4.2 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from "@nestjs/common";
|
|
import { ApiBearerAuth, ApiOperation, ApiParam, ApiTags } from "@nestjs/swagger";
|
|
|
|
import { ContactService } from "./providers/contact.service";
|
|
import { IconsService } from "./providers/icons.service";
|
|
import { RestaurantService } from "./providers/restaurant.service";
|
|
import { CreateIconDto } from "./DTO/create-icon.dto";
|
|
import { UpdateIconDto } from "./DTO/update-icon.dto";
|
|
import { CreateGroupDto } from "./DTO/create-group.dto";
|
|
import { UpdateGroupDto } from "./DTO/update-group.dto";
|
|
import { FindRestaurantsDto } from "./DTO/find-restaurants.dto";
|
|
import { CreateRestaurantDto } from "./DTO/create-restaurant.dto";
|
|
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
|
import { PermissionsDec } from "../../common/decorators/permission.decorator";
|
|
import { PermissionEnum } from "../users/enums/permission.enum";
|
|
import { UserDec } from "../../common/decorators/user.decorator";
|
|
|
|
@ApiTags("d-menu")
|
|
@Controller("admin/dmenu")
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.DMENU)
|
|
@ApiBearerAuth()
|
|
export class DmenuController {
|
|
constructor(
|
|
private readonly iconsService: IconsService,
|
|
private readonly contactService: ContactService,
|
|
private readonly restaurantService: RestaurantService,
|
|
) { }
|
|
|
|
// Icon endpoints
|
|
@Post('icons')
|
|
@ApiOperation({ summary: "Create icon" })
|
|
createIcon(@Body() dto: CreateIconDto) {
|
|
return this.iconsService.createIcon(dto);
|
|
}
|
|
|
|
@Get('icons')
|
|
@ApiOperation({ summary: "Get all icons" })
|
|
findAllIcons() {
|
|
return this.iconsService.findAllIcons();
|
|
}
|
|
// Group endpoints: place BEFORE `icons/:id` routes to avoid route conflicts
|
|
@Post("icons/groups")
|
|
@ApiOperation({ summary: "Create icon group" })
|
|
createGroup(@Body() dto: CreateGroupDto) {
|
|
return this.iconsService.createGroup(dto);
|
|
}
|
|
|
|
@Get("icons/groups")
|
|
@ApiOperation({ summary: "Get all icon groups" })
|
|
findAllGroups() {
|
|
return this.iconsService.findAllGroups();
|
|
}
|
|
|
|
@Get("icons/groups/:id")
|
|
@ApiOperation({ summary: "Get icon group by id" })
|
|
@ApiParam({ name: "id", required: true, type: String })
|
|
findOneGroup(@Param("id") id: string) {
|
|
return this.iconsService.findOneGroup(id);
|
|
}
|
|
|
|
@Patch("icons/groups/:id")
|
|
@ApiOperation({ summary: "Update icon group" })
|
|
@ApiParam({ name: "id" })
|
|
updateGroup(@Param("id") id: string, @Body() dto: UpdateGroupDto) {
|
|
return this.iconsService.updateGroup(id, dto);
|
|
}
|
|
|
|
@Delete("icons/groups/:id")
|
|
@ApiOperation({ summary: "Delete icon group" })
|
|
@ApiParam({ name: "id" })
|
|
removeGroup(@Param("id") id: string) {
|
|
return this.iconsService.removeGroup(id);
|
|
}
|
|
|
|
@Get("icons/:id")
|
|
@ApiOperation({ summary: "Get icon by id" })
|
|
@ApiParam({ name: "id", required: true, type: String })
|
|
findOneIcon(@Param("id") id: string) {
|
|
return this.iconsService.findOneIcon(id);
|
|
}
|
|
|
|
@Patch("icons/:id")
|
|
@ApiOperation({ summary: "Update icon" })
|
|
@ApiParam({ name: "id" })
|
|
updateIcon(@Param("id") id: string, @Body() dto: UpdateIconDto) {
|
|
return this.iconsService.updateIcon(id, dto);
|
|
}
|
|
|
|
@Delete("icons/:id")
|
|
@ApiOperation({ summary: "Delete icon" })
|
|
@ApiParam({ name: "id" })
|
|
removeIcon(@Param("id") id: string) {
|
|
return this.iconsService.removeIcon(id);
|
|
}
|
|
// contacts
|
|
@Get('contacts')
|
|
findAll() {
|
|
return this.contactService.findAll();
|
|
}
|
|
|
|
@Get("contacts/:id")
|
|
findOne(@Param("id") id: string) {
|
|
return this.contactService.findOne(+id);
|
|
}
|
|
|
|
// restaurant
|
|
@Get('restaurants')
|
|
@ApiOperation({ summary: "Get all restaurants" })
|
|
findAllRestaurant(@Query() queryDto: FindRestaurantsDto) {
|
|
return this.restaurantService.findAll(queryDto);
|
|
}
|
|
|
|
@Post('restaurants')
|
|
@ApiOperation({ summary: "Create restaurant" })
|
|
createRestaurant(@Body() dto: CreateRestaurantDto, @UserDec("id") userId: string) {
|
|
return this.restaurantService.createRestaurant(dto, userId);
|
|
}
|
|
|
|
@Get('/super-admin/restaurants/subscription/:subscriptionId')
|
|
@ApiOperation({ summary: "Get restaurant subscription by subscription ID" })
|
|
@ApiParam({ name: "subscriptionId", required: true, type: String })
|
|
getRestaurantSubscription(@Param("subscriptionId") subscriptionId: string) {
|
|
return this.restaurantService.getRestaurantSubscription(subscriptionId);
|
|
}
|
|
}
|