notification module
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { TicketService } from './ticket.service';
|
||||
import { CreateTicketDto } from './dto/create-ticket.dto';
|
||||
import { UpdateTicketDto } from './dto/update-ticket.dto';
|
||||
import { CreateTicketUserDto } from './dto/create-ticket-user.dto';
|
||||
import { UpdateTicketUserDto } from './dto/update-ticket-user.dto';
|
||||
import { SearchTicketQueryDto } from './dto/search-ticket-query.dto';
|
||||
import { AdminAuthGuard } from '../auth/guards/adminAuth.guard';
|
||||
import { AuthGuard } from '../auth/guards/auth.guard';
|
||||
import { Permissions } from 'src/common/decorators/permissions.decorator';
|
||||
import { PermissionEnum } from 'src/common/enums/permission.enum';
|
||||
import { UserId } from 'src/common/decorators/user-id.decorator';
|
||||
import { AdminId } from 'src/common/decorators/admin-id.decorator';
|
||||
|
||||
@ApiTags('Ticket')
|
||||
@ApiBearerAuth()
|
||||
@Controller()
|
||||
export class TicketController {
|
||||
constructor(private readonly ticketService: TicketService) { }
|
||||
|
||||
// ================== User routes ===================
|
||||
|
||||
@Post('public/tickets')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Create a ticket (as user)' })
|
||||
createAsUser(@Body() createTicketUserDto: CreateTicketUserDto, @UserId() userId: string) {
|
||||
return this.ticketService.createAsUser(createTicketUserDto, userId);
|
||||
}
|
||||
|
||||
@Get('public/tickets')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Get my tickets with pagination' })
|
||||
findMyTickets(@Query() queryDto: SearchTicketQueryDto, @UserId() userId: string) {
|
||||
return this.ticketService.findMyTickets(userId, queryDto);
|
||||
}
|
||||
|
||||
@Get('public/tickets/:id')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Get one of my tickets by id' })
|
||||
findOneAsUser(@Param('id') id: string, @UserId() userId: string) {
|
||||
return this.ticketService.findOneAsUser(id, userId);
|
||||
}
|
||||
|
||||
@Patch('public/tickets/:id')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Update a ticket (as user, own tickets only)' })
|
||||
updateAsUser(
|
||||
@Param('id') id: string,
|
||||
@Body() updateTicketUserDto: UpdateTicketUserDto,
|
||||
@UserId() userId: string,
|
||||
) {
|
||||
return this.ticketService.updateAsUser(id, updateTicketUserDto, userId);
|
||||
}
|
||||
|
||||
// ================== Admin routes ===================
|
||||
|
||||
@Post('admin/tickets')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(PermissionEnum.MANAGE_TICKETS)
|
||||
@ApiOperation({ summary: 'Create a ticket (as admin)' })
|
||||
createAsAdmin(@Body() dto: CreateTicketDto, @AdminId() adminId: string) {
|
||||
return this.ticketService.createAsAdmin(dto, adminId);
|
||||
}
|
||||
|
||||
@Get('admin/tickets')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(PermissionEnum.MANAGE_TICKETS)
|
||||
@ApiOperation({ summary: 'Get all tickets with pagination' })
|
||||
findAllAsAdmin(@Query() queryDto: SearchTicketQueryDto) {
|
||||
return this.ticketService.findAll(queryDto);
|
||||
}
|
||||
|
||||
@Get('admin/tickets/:id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(PermissionEnum.MANAGE_TICKETS)
|
||||
@ApiOperation({ summary: 'Get one ticket by id' })
|
||||
findOneAsAdmin(@Param('id') id: string) {
|
||||
return this.ticketService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch('admin/tickets/:id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(PermissionEnum.MANAGE_TICKETS)
|
||||
@ApiOperation({ summary: 'Update a ticket (as admin)' })
|
||||
updateAsAdmin(@Param('id') id: string, @Body() updateTicketDto: UpdateTicketDto) {
|
||||
return this.ticketService.update(id, updateTicketDto);
|
||||
}
|
||||
|
||||
@Delete('admin/tickets/:id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(PermissionEnum.MANAGE_TICKETS)
|
||||
@ApiOperation({ summary: 'Soft delete a ticket' })
|
||||
remove(@Param('id') id: string) {
|
||||
return this.ticketService.remove(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user