Compare commits

..

No commits in common. "4349a1b61a2bdacb5ff69b84880b5d43eebd21e9" and "65d5ce3bc2f41f1dd7277f34b69dbb5717e5ba5f" have entirely different histories.

5 changed files with 2 additions and 72 deletions

View File

@ -1,12 +0,0 @@
-- AlterTable
ALTER TABLE "ChallengeAction" ALTER COLUMN "end" SET DATA TYPE TIMESTAMPTZ(3),
ALTER COLUMN "penaltyEnd" SET DATA TYPE TIMESTAMPTZ(3),
ALTER COLUMN "penaltyStart" SET DATA TYPE TIMESTAMPTZ(3),
ALTER COLUMN "start" SET DATA TYPE TIMESTAMPTZ(3);
-- AlterTable
ALTER TABLE "Geolocation" ALTER COLUMN "timestamp" SET DATA TYPE TIMESTAMPTZ(3);
-- AlterTable
ALTER TABLE "TrainTrip" ALTER COLUMN "departureTime" SET DATA TYPE TIMESTAMPTZ(3),
ALTER COLUMN "arrivalTime" SET DATA TYPE TIMESTAMPTZ(3);

View File

@ -9,7 +9,6 @@ import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
import { PaginateOutputDto } from 'src/common/dto/pagination-output.dto' import { PaginateOutputDto } from 'src/common/dto/pagination-output.dto'
import { UpdateChallengeActionDto } from './dto/update-challenge-action.dto' import { UpdateChallengeActionDto } from './dto/update-challenge-action.dto'
import { FilterChallengeActionsDto } from './dto/filter-challenge-action.dto' import { FilterChallengeActionsDto } from './dto/filter-challenge-action.dto'
import { EndChallengeActionDto } from './dto/end-challenge-action.dto'
@Controller('challenge-actions') @Controller('challenge-actions')
export class ChallengeActionsController { export class ChallengeActionsController {
@ -75,16 +74,4 @@ export class ChallengeActionsController {
async remove(@Param('id', ParseIntPipe) id: number) { async remove(@Param('id', ParseIntPipe) id: number) {
await this.challengeActionsService.remove(id) await this.challengeActionsService.remove(id)
} }
@Post('/end-current')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOkResponse({ type: ChallengeActionEntity })
@ApiUnauthorizedResponse({ description: "Non authentifié⋅e" })
@ApiForbiddenResponse({ description: "Permission refusée" })
@ApiNotFoundResponse({ description: "Objet non trouvé" })
async endCurrent(@Req() request: AuthenticatedRequest, @Body() { success }: EndChallengeActionDto): Promise<ChallengeActionEntity> {
const challengeAction = await this.challengeActionsService.endCurrentChallenge(request.user, success)
return new ChallengeActionEntity(challengeAction)
}
} }

View File

@ -1,4 +1,4 @@
import { Injectable, NotAcceptableException } from '@nestjs/common' import { Injectable } from '@nestjs/common'
import { CreateChallengeActionDto } from './dto/create-challenge-action.dto' import { CreateChallengeActionDto } from './dto/create-challenge-action.dto'
import { UpdateChallengeActionDto } from './dto/update-challenge-action.dto' import { UpdateChallengeActionDto } from './dto/update-challenge-action.dto'
import { ChallengeAction, User } from '@prisma/client' import { ChallengeAction, User } from '@prisma/client'
@ -48,39 +48,4 @@ export class ChallengeActionsService {
where: { id }, where: { id },
}) })
} }
async endCurrentChallenge(user: User, success: boolean): Promise<ChallengeAction> {
const challengeAction = await this.prisma.challengeAction.findFirst({
where: {
userId: user.id,
active: true,
}
})
if (!challengeAction)
throw new NotAcceptableException("Aucun défi n'est en cours")
let data
const now = new Date()
if (success) {
data = {
success: success,
active: false,
end: now,
}
}
else {
data = {
success: success,
active: false,
end: now,
penaltyStart: now,
penaltyEnd: new Date(now.getTime() + 45 * 60 * 1000),
}
}
return await this.prisma.challengeAction.update({
where: {
id: challengeAction.id,
},
data: data,
})
}
} }

View File

@ -1,10 +0,0 @@
import { ApiProperty } from "@nestjs/swagger"
import { IsBoolean } from "class-validator"
import { BooleanTransform } from "src/common/utils/transform.utils"
export class EndChallengeActionDto {
@IsBoolean()
@BooleanTransform()
@ApiProperty({ description: "Indique si le défi a été un succès ou non." })
success: boolean
}

View File

@ -2,7 +2,7 @@ import { ApiProperty } from "@nestjs/swagger"
import { ChallengeAction } from "@prisma/client" import { ChallengeAction } from "@prisma/client"
import { IsOptional } from "class-validator" import { IsOptional } from "class-validator"
export class ChallengeActionEntity implements ChallengeAction { export default class ChallengeActionEntity implements ChallengeAction {
constructor(partial: Partial<ChallengeActionEntity>) { constructor(partial: Partial<ChallengeActionEntity>) {
Object.assign(this, partial) Object.assign(this, partial)
} }