diff --git a/server/src/challenge-actions/challenge-actions.controller.ts b/server/src/challenge-actions/challenge-actions.controller.ts index c972202..56157ba 100644 --- a/server/src/challenge-actions/challenge-actions.controller.ts +++ b/server/src/challenge-actions/challenge-actions.controller.ts @@ -1,7 +1,7 @@ import { Controller, Get, Post, Body, Patch, Param, Delete, ParseIntPipe, HttpCode, UseGuards, Req, Query, NotFoundException } from '@nestjs/common' import { ChallengeActionsService } from './challenge-actions.service' import { AuthenticatedRequest, JwtAuthGuard } from 'src/auth/jwt-auth.guard' -import { ApiBearerAuth, ApiCreatedResponse, ApiNotFoundResponse, ApiOkResponse, ApiUnauthorizedResponse, ApiUnprocessableEntityResponse } from '@nestjs/swagger' +import { ApiBearerAuth, ApiConflictResponse, ApiCreatedResponse, ApiNotFoundResponse, ApiOkResponse, ApiUnauthorizedResponse } from '@nestjs/swagger' import { ChallengeActionEntity } from './entities/challenge-action.entity' import { CreateChallengeActionDto } from './dto/create-challenge-action.dto' import { ApiOkResponsePaginated, paginateOutput } from 'src/common/utils/pagination.utils' @@ -76,6 +76,7 @@ export class ChallengeActionsController { @ApiOkResponse({ type: ChallengeActionEntity }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) @ApiNotFoundResponse({ description: "Objet non trouvé" }) + @ApiConflictResponse({ description: "Aucun défi à terminer n'est en cours" }) async endCurrent(@Req() request: AuthenticatedRequest, @Body() { success }: EndChallengeActionDto): Promise { const challengeAction = await this.challengeActionsService.endCurrentChallenge(request.user, success) return new ChallengeActionEntity(challengeAction) diff --git a/server/src/challenge-actions/challenge-actions.service.ts b/server/src/challenge-actions/challenge-actions.service.ts index bedc7e6..2ef16c9 100644 --- a/server/src/challenge-actions/challenge-actions.service.ts +++ b/server/src/challenge-actions/challenge-actions.service.ts @@ -1,4 +1,4 @@ -import { Injectable, NotAcceptableException } from '@nestjs/common' +import { BadRequestException, Injectable, UnprocessableEntityException } from '@nestjs/common' import { CreateChallengeActionDto } from './dto/create-challenge-action.dto' import { UpdateChallengeActionDto } from './dto/update-challenge-action.dto' import { ChallengeAction, Player } from '@prisma/client' @@ -55,7 +55,7 @@ export class ChallengeActionsService { } }) if (!challengeAction) - throw new NotAcceptableException("Aucun défi n'est en cours") + throw new BadRequestException("Aucun défi n'est en cours") let data const now = new Date() if (success) { diff --git a/server/src/challenges/challenges.controller.ts b/server/src/challenges/challenges.controller.ts index 8c62a09..3548bf3 100644 --- a/server/src/challenges/challenges.controller.ts +++ b/server/src/challenges/challenges.controller.ts @@ -3,7 +3,7 @@ import { ChallengesService } from './challenges.service' import { CreateChallengeDto } from './dto/create-challenge.dto' import { UpdateChallengeDto } from './dto/update-challenge.dto' import { AuthenticatedRequest, JwtAuthGuard } from 'src/auth/jwt-auth.guard' -import { ApiBearerAuth, ApiCreatedResponse, ApiForbiddenResponse, ApiNotFoundResponse, ApiOkResponse, ApiUnauthorizedResponse } from '@nestjs/swagger' +import { ApiBearerAuth, ApiConflictResponse, ApiCreatedResponse, ApiNotFoundResponse, ApiOkResponse, ApiUnauthorizedResponse } from '@nestjs/swagger' import { ChallengeEntity } from './entities/challenge.entity' import { ApiOkResponsePaginated, paginateOutput } from 'src/common/utils/pagination.utils' import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto' @@ -19,7 +19,6 @@ export class ChallengesController { @ApiBearerAuth() @ApiCreatedResponse({ type: ChallengeEntity, description: "Objet créé avec succès" }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) - @ApiForbiddenResponse({ description: "Permission refusée" }) async create(@Body() createChallengeDto: CreateChallengeDto): Promise { const challenge = await this.challengesService.create(createChallengeDto) return new ChallengeEntity(challenge) @@ -30,7 +29,6 @@ export class ChallengesController { @ApiBearerAuth() @ApiOkResponsePaginated(ChallengeEntity) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) - @ApiForbiddenResponse({ description: "Permission refusée" }) async findAll(@Query() queryPagination?: QueryPaginationDto): Promise> { const [challenges, total] = await this.challengesService.findAll(queryPagination) return paginateOutput(challenges.map(challenge => new ChallengeEntity(challenge)), total, queryPagination) @@ -41,7 +39,6 @@ export class ChallengesController { @ApiBearerAuth() @ApiOkResponse({ type: ChallengeEntity }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) - @ApiForbiddenResponse({ description: "Permission refusée" }) @ApiNotFoundResponse({ description: "Objet non trouvé" }) async findOne(@Param('id', ParseIntPipe) id: number): Promise { const challenge = await this.challengesService.findOne(id) @@ -55,7 +52,6 @@ export class ChallengesController { @ApiBearerAuth() @ApiOkResponse({ type: ChallengeEntity }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) - @ApiForbiddenResponse({ description: "Permission refusée" }) @ApiNotFoundResponse({ description: "Objet non trouvé" }) async update(@Param('id', ParseIntPipe) id: number, @Body() updateChallengeDto: UpdateChallengeDto) { return await this.challengesService.update(id, updateChallengeDto) @@ -67,7 +63,6 @@ export class ChallengesController { @ApiBearerAuth() @ApiOkResponse({ type: ChallengeEntity }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) - @ApiForbiddenResponse({ description: "Permission refusée" }) @ApiNotFoundResponse({ description: "Objet non trouvé" }) async remove(@Param('id', ParseIntPipe) id: number) { await this.challengesService.remove(id) @@ -78,8 +73,8 @@ export class ChallengesController { @ApiBearerAuth() @ApiOkResponse({ type: ChallengeEntity }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) - @ApiForbiddenResponse({ description: "Permission refusée" }) @ApiNotFoundResponse({ description: "Objet non trouvé" }) + @ApiConflictResponse({ description: "Un défi est déjà en cours d'accomplissement" }) async drawRandom(@Req() request: AuthenticatedRequest): Promise { const challenge = await this.challengesService.drawRandom(request.user) return new ChallengeEntity(challenge) diff --git a/server/src/challenges/challenges.service.ts b/server/src/challenges/challenges.service.ts index 2639cee..67db055 100644 --- a/server/src/challenges/challenges.service.ts +++ b/server/src/challenges/challenges.service.ts @@ -1,4 +1,4 @@ -import { Injectable, NotAcceptableException, NotFoundException } from '@nestjs/common' +import { ConflictException, Injectable, NotFoundException } from '@nestjs/common' import { CreateChallengeDto } from './dto/create-challenge.dto' import { UpdateChallengeDto } from './dto/update-challenge.dto' import { Challenge, Player } from '@prisma/client' @@ -64,7 +64,7 @@ export class ChallengesService { } }) if (currentChallengeAction) - throw new NotAcceptableException("Un défi est déjà en cours d'accomplissement") + throw new ConflictException("Un défi est déjà en cours d'accomplissement") const remaningChallenges = await this.prisma.challenge.count({ where: { action: null, diff --git a/server/src/trains/trains.controller.ts b/server/src/trains/trains.controller.ts index 8039c4c..c06fd4f 100644 --- a/server/src/trains/trains.controller.ts +++ b/server/src/trains/trains.controller.ts @@ -4,7 +4,7 @@ import { CreateTrainDto } from './dto/create-train.dto' import { UpdateTrainDto } from './dto/update-train.dto' import { TrainEntity } from './entities/train.entity' import { AuthenticatedRequest, JwtAuthGuard } from 'src/auth/jwt-auth.guard' -import { ApiBearerAuth, ApiCreatedResponse, ApiNotFoundResponse, ApiOkResponse, ApiUnauthorizedResponse } from '@nestjs/swagger' +import { ApiBearerAuth, ApiCreatedResponse, ApiNotFoundResponse, ApiOkResponse, ApiUnauthorizedResponse, ApiUnprocessableEntityResponse } from '@nestjs/swagger' import { ApiOkResponsePaginated, paginateOutput } from 'src/common/utils/pagination.utils' import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto' import { PaginateOutputDto } from 'src/common/dto/pagination-output.dto' @@ -76,6 +76,7 @@ export class TrainsController { @ApiBearerAuth() @ApiCreatedResponse({ type: TrainEntity, description: "Train importé avec succès" }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) + @ApiUnprocessableEntityResponse({ description: "Le voyage Interrail à importer contient plusieurs trajets ou plusieurs trains" }) async import(@Req() request: AuthenticatedRequest, @Body() importTrainDto: ImportTrainDto): Promise { const train = await this.trainsService.import(request.user, importTrainDto) return new TrainEntity(train) diff --git a/server/src/trains/trains.service.ts b/server/src/trains/trains.service.ts index 300e329..eafce5a 100644 --- a/server/src/trains/trains.service.ts +++ b/server/src/trains/trains.service.ts @@ -1,4 +1,4 @@ -import { Injectable, NotAcceptableException } from '@nestjs/common' +import { Injectable, UnprocessableEntityException } from '@nestjs/common' import { CreateTrainDto } from './dto/create-train.dto' import { UpdateTrainDto } from './dto/update-train.dto' import { PrismaService } from 'src/prisma/prisma.service' @@ -53,10 +53,10 @@ export class TrainsService { const interrailResult: InterrailJourney = await fetch(`https://3uiwjsimnh.execute-api.eu-central-1.amazonaws.com/Prod/journey-import?id=${trainId}`) .then(data => data.json()) if (interrailResult.data.travels.length !== 1) - throw new NotAcceptableException(`Ce voyage contient ${interrailResult.data.travels.length} trajets. Merci d'ajouter les trajets un à un.`) + throw new UnprocessableEntityException(`Ce voyage contient ${interrailResult.data.travels.length} trajets. Merci d'ajouter les trajets un à un.`) const travel = interrailResult.data.travels[0] if (travel.legs.length !== 1) - throw new NotAcceptableException(`Ce trajet contient ${travel.legs.length} trains. Merci d'ajouter les trajets un à un.`) + throw new UnprocessableEntityException(`Ce trajet contient ${travel.legs.length} trains. Merci d'ajouter les trajets un à un.`) const leg = travel.legs[0] const travelInfoJson: InterrailTravelInfo = JSON.parse(travel.infoJson)