Files
negareh-api/src/modules/ticket/controller/ticket.controller.ts
T
2026-01-31 11:40:28 +03:30

79 lines
3.3 KiB
TypeScript
Executable File

import { Body, Controller, Delete, Get, Param, Patch, Post, Query, UseGuards } from "@nestjs/common";
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger";
import { CreateTicketDto } from "../DTO/create-ticket.dto";
import { FindTicketQueryDto } from "../DTO/search-ticket-query.dto";
import { TicketService } from "../providers/tickets.service";
import { UserId } from "src/common/decorators";
import { AdminId } from "src/common/decorators/admin-id.decorator";
import { UpdateTicketDto } from "../DTO/update-ticket.dto";
import { AdminAuthGuard } from "src/modules/auth/guards/adminAuth.guard";
import { AuthGuard } from "src/modules/auth/guards/auth.guard";
@Controller()
@ApiTags("Tickets")
@ApiBearerAuth()
export class TicketController {
constructor(private readonly ticketsService: TicketService) { }
@Post('public/ticket/order/item/:id')
@UseGuards(AuthGuard)
@ApiOperation({ summary: "create ticket ==> user route" })
createTicket(@Param('id') itemId: string, @Body() createDto: CreateTicketDto, @UserId() userId: string) {
return this.ticketsService.createTicketAsUser(itemId, createDto, userId);
}
@Get('public/ticket/order/:orderId')
@UseGuards(AuthGuard)
@ApiOperation({ summary: "Get all order tickets ==> user route" })
getTickets(@Query() queryDto: FindTicketQueryDto, @Param('orderId') orderId: string, @UserId() userId: string) {
return this.ticketsService.getTickets(orderId, queryDto, userId);
}
@Delete('public/ticket/:ticketId')
@ApiOperation({ summary: "Delete Ticket ==> admin route" })
@UseGuards(AuthGuard)
deleteTicket(@Param('ticketId') ticketId: string, @UserId() userId: string) {
return this.ticketsService.deleteTicketAsUSer(+ticketId, userId);
}
@Patch('public/ticket/:ticketId')
@UseGuards(AuthGuard)
@ApiOperation({ summary: "Delete Ticket ==> admin route" })
updateTicket(@Param('ticketId') ticketId: string, @UserId() userId: string, @Body() body: UpdateTicketDto) {
return this.ticketsService.updateTicketAsUser(+ticketId, userId, body);
}
/*=========================== Admin ============================== */
@Delete('admin/ticket/:ticketId')
@UseGuards(AdminAuthGuard)
@ApiOperation({ summary: "Delete Ticket ==> admin route" })
deleteTicketAsAdmin(@Param('ticketId') ticketId: string, @AdminId() adminId: string) {
return this.ticketsService.deleteTicketAsAdmin(+ticketId, adminId);
}
@Post('admin/ticket/order/item/:id')
@UseGuards(AdminAuthGuard)
@ApiOperation({ summary: "create ticket ==> admin route" })
createTicketAsAdmin(@Param('id') orderItemId: string, @Body() createDto: CreateTicketDto, @AdminId() adminId: string) {
return this.ticketsService.createTicketAsAdmin(orderItemId, createDto, adminId);
}
@Get('admin/ticket/order/:orderId')
@UseGuards(AdminAuthGuard)
@ApiOperation({ summary: "Get all order tickets ==> admin route" })
getTicketsAsAdmin(@Query() queryDto: FindTicketQueryDto, @Param('orderId') orderId: string) {
return this.ticketsService.getTickets(orderId, queryDto);
}
@Patch('admin/ticket/:ticketId')
@UseGuards(AdminAuthGuard)
@ApiOperation({ summary: "Delete Ticket ==> admin route" })
updateTicketAsAdmin(@Param('ticketId') ticketId: string, @AdminId() adminId: string, @Body() body: UpdateTicketDto) {
return this.ticketsService.updateTicketAsAdmin(+ticketId, adminId, body);
}
}