2024-12-08 01:23:37 +00:00
|
|
|
import { Controller, Get, Post, Body, Patch, Param, Delete, HttpCode, UseGuards, Query, NotFoundException, ParseIntPipe, Req } from '@nestjs/common'
|
|
|
|
import { MoneyUpdatesService } from './money-updates.service'
|
|
|
|
import { CreateMoneyUpdateDto } from './dto/create-money-update.dto'
|
|
|
|
import { UpdateMoneyUpdateDto } from './dto/update-money-update.dto'
|
|
|
|
import { AuthenticatedRequest, JwtAuthGuard } from 'src/auth/jwt-auth.guard'
|
2024-12-08 17:18:11 +00:00
|
|
|
import { ApiBearerAuth, ApiNoContentResponse } from '@nestjs/swagger'
|
2024-12-08 01:23:37 +00:00
|
|
|
import { MoneyUpdateEntity } from './entities/money-update.entity'
|
|
|
|
import { ApiOkResponsePaginated, paginateOutput } from 'src/common/utils/pagination.utils'
|
|
|
|
import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
|
2024-12-08 12:41:37 +00:00
|
|
|
import { PlayerFilterDto } from 'src/common/dto/player_filter.dto'
|
2024-12-08 01:23:37 +00:00
|
|
|
import { PaginateOutputDto } from 'src/common/dto/pagination-output.dto'
|
|
|
|
|
|
|
|
@Controller('money-updates')
|
|
|
|
export class MoneyUpdatesController {
|
|
|
|
constructor(private readonly moneyUpdatesService: MoneyUpdatesService) {}
|
|
|
|
|
2024-12-08 17:18:11 +00:00
|
|
|
/**
|
|
|
|
* Création d'une modification de solde
|
|
|
|
*
|
|
|
|
* @throws {400} Erreurs dans le formulaire de création
|
|
|
|
* @throws {401} Non authentifié⋅e
|
|
|
|
*/
|
2024-12-08 01:23:37 +00:00
|
|
|
@Post()
|
|
|
|
@HttpCode(201)
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
@ApiBearerAuth()
|
|
|
|
async create(@Req() request: AuthenticatedRequest, @Body() createMoneyUpdateDto: CreateMoneyUpdateDto): Promise<MoneyUpdateEntity> {
|
|
|
|
const moneyUpdate = await this.moneyUpdatesService.create(request.user, createMoneyUpdateDto)
|
|
|
|
return new MoneyUpdateEntity(moneyUpdate)
|
|
|
|
}
|
|
|
|
|
2024-12-08 17:18:11 +00:00
|
|
|
/**
|
|
|
|
* Recherche de modifications de solde
|
|
|
|
*
|
|
|
|
* @throws {401} Non authentifié⋅e
|
|
|
|
*/
|
2024-12-08 01:23:37 +00:00
|
|
|
@Get()
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
@ApiBearerAuth()
|
|
|
|
@ApiOkResponsePaginated(MoneyUpdateEntity)
|
2024-12-08 12:41:37 +00:00
|
|
|
async findAll(@Query() queryPagination: QueryPaginationDto, @Query() playerFilter: PlayerFilterDto): Promise<PaginateOutputDto<MoneyUpdateEntity>> {
|
|
|
|
const [trains, total] = await this.moneyUpdatesService.findAll(queryPagination, playerFilter)
|
2024-12-08 01:23:37 +00:00
|
|
|
return paginateOutput<MoneyUpdateEntity>(trains.map(train => new MoneyUpdateEntity(train)), total, queryPagination)
|
|
|
|
}
|
|
|
|
|
2024-12-08 17:18:11 +00:00
|
|
|
/**
|
|
|
|
* Recherche d'une modification de solde
|
|
|
|
*
|
|
|
|
* @throws {401} Non authentifié⋅e
|
|
|
|
* @throws {404} Modification de solde non trouvée
|
|
|
|
*/
|
2024-12-08 01:23:37 +00:00
|
|
|
@Get(':id')
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
@ApiBearerAuth()
|
|
|
|
async findOne(@Param('id', ParseIntPipe) id: number): Promise<MoneyUpdateEntity> {
|
|
|
|
const train = await this.moneyUpdatesService.findOne(id)
|
|
|
|
if (!train)
|
|
|
|
throw new NotFoundException(`Trajet en train inexistant avec l'identifiant ${id}`)
|
|
|
|
return new MoneyUpdateEntity(train)
|
|
|
|
}
|
|
|
|
|
2024-12-08 17:18:11 +00:00
|
|
|
/**
|
|
|
|
* Modification d'une modification de solde
|
|
|
|
*
|
|
|
|
* @throws {400} Erreurs dans le formulaire de modification
|
|
|
|
* @throws {401} Non authentifié⋅e
|
|
|
|
* @throws {404} Modification de solde non trouvée
|
|
|
|
*/
|
2024-12-08 01:23:37 +00:00
|
|
|
@Patch(':id')
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
@ApiBearerAuth()
|
|
|
|
async update(@Param('id', ParseIntPipe) id: number, @Body() updateMoneyUpdateDto: UpdateMoneyUpdateDto) {
|
|
|
|
return await this.moneyUpdatesService.update(id, updateMoneyUpdateDto)
|
|
|
|
}
|
|
|
|
|
2024-12-08 17:18:11 +00:00
|
|
|
/**
|
|
|
|
* Suppression d'une modification de solde
|
|
|
|
*
|
|
|
|
* @throws {401} Non authentifié⋅e
|
|
|
|
* @throws {404} Modification de solde non trouvée
|
|
|
|
*/
|
2024-12-08 01:23:37 +00:00
|
|
|
@Delete(':id')
|
|
|
|
@HttpCode(204)
|
|
|
|
@UseGuards(JwtAuthGuard)
|
2024-12-08 17:18:11 +00:00
|
|
|
@ApiNoContentResponse({ description: "La modification de solde a bien été supprimée" })
|
2024-12-08 01:23:37 +00:00
|
|
|
@ApiBearerAuth()
|
|
|
|
async remove(@Param('id', ParseIntPipe) id: number) {
|
|
|
|
await this.moneyUpdatesService.remove(id)
|
|
|
|
}
|
|
|
|
}
|