64 lines
3.0 KiB
TypeScript
64 lines
3.0 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Patch, Post, UseGuards } from '@nestjs/common';
|
|
import { OAuthSessions } from '@prisma/client';
|
|
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
|
import { Roles as RoleEnum } from '.prisma/client';
|
|
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
import { JwtAuthGuard } from 'src/modules/authentication/guards/jwt-auth.guard';
|
|
import { CreateOauthSessionDto } from '../dtos/create-oauth-sessions.dto';
|
|
import { OauthSessionsService } from '../services/oauth-sessions.service';
|
|
import { OAuthSessionEntity } from '../dtos/swagger-entities/oauth-sessions.entity';
|
|
import { UpdateOauthSessionDto } from '../dtos/update-oauth-sessions.dto';
|
|
|
|
@ApiTags('OAuth Sessions')
|
|
@ApiBearerAuth('sessions')
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('oauth-sessions')
|
|
export class OauthSessionsController {
|
|
constructor(private readonly oauthSessionsService: OauthSessionsService){}
|
|
|
|
@Post()
|
|
@RolesAllowed(RoleEnum.ADMIN)
|
|
@ApiOperation({summary: 'Create OAuth session' })
|
|
@ApiResponse({ status: 201, description: 'OAuth session created', type: OAuthSessionEntity })
|
|
@ApiResponse({ status: 400, description: 'Incomplete task or invalid data' })
|
|
create(@Body()dto: CreateOauthSessionDto): Promise<OAuthSessions> {
|
|
return this.oauthSessionsService.create(dto);
|
|
}
|
|
|
|
@Get()
|
|
@RolesAllowed(RoleEnum.ADMIN)
|
|
@ApiOperation({summary: 'Find all OAuth session' })
|
|
@ApiResponse({ status: 201, description: 'List of OAuth session found', type: OAuthSessionEntity, isArray: true })
|
|
@ApiResponse({ status: 400, description: 'List of OAuth session not found' })
|
|
findAll(): Promise<OAuthSessions[]> {
|
|
return this.oauthSessionsService.findAll();
|
|
}
|
|
|
|
@Get(':id')
|
|
@RolesAllowed(RoleEnum.ADMIN)
|
|
@ApiOperation({summary: 'Find OAuth session' })
|
|
@ApiResponse({ status: 201, description: 'OAuth session found', type: OAuthSessionEntity })
|
|
@ApiResponse({ status: 400, description: 'OAuth session not found' })
|
|
findOne(@Param('id') id: string): Promise<OAuthSessions> {
|
|
return this.oauthSessionsService.findOne(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@RolesAllowed(RoleEnum.ADMIN)
|
|
@ApiOperation({summary: 'Update OAuth session' })
|
|
@ApiResponse({ status: 201, description: 'OAuth session updated', type: OAuthSessionEntity })
|
|
@ApiResponse({ status: 400, description: 'OAuth session not found' })
|
|
update(@Param('id') id: string, @Body() dto: UpdateOauthSessionDto): Promise<OAuthSessions> {
|
|
return this.oauthSessionsService.update(id,dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@RolesAllowed(RoleEnum.ADMIN)
|
|
@ApiOperation({summary: 'Delete OAuth session' })
|
|
@ApiResponse({ status: 201, description: 'OAuth session deleted', type: OAuthSessionEntity })
|
|
@ApiResponse({ status: 400, description: 'OAuth session not found' })
|
|
remove(@Param('id') id: string): Promise<OAuthSessions> {
|
|
return this.oauthSessionsService.remove(id);
|
|
}
|
|
}
|