From c82d39c009b797ec93a186625a5c116097c75737 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sat, 7 Dec 2024 19:47:13 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20du=20d=C3=A9fi=20dans=20le=20retour=20d?= =?UTF-8?q?'une=20action=20de=20d=C3=A9fi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challenge-actions.service.ts | 19 ++++++++++++++++--- .../dto/create-challenge-action.dto.ts | 12 +++++++----- .../entities/challenge-action.entity.ts | 7 +++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/server/src/challenge-actions/challenge-actions.service.ts b/server/src/challenge-actions/challenge-actions.service.ts index 0265143..d939e03 100644 --- a/server/src/challenge-actions/challenge-actions.service.ts +++ b/server/src/challenge-actions/challenge-actions.service.ts @@ -12,20 +12,31 @@ export class ChallengeActionsService { async create(authenticatedUser: User, createChallengeActionDto: CreateChallengeActionDto): Promise { const data = { ...createChallengeActionDto, userId: authenticatedUser.id } - return await this.prisma.challengeAction.create({ data: data }) + return await this.prisma.challengeAction.create({ + data: data, + include: { challenge: true }, + }) } async findAll(queryPagination?: QueryPaginationDto): Promise<[ChallengeAction[], number]> { return [ await this.prisma.challengeAction.findMany({ ...paginate(queryPagination), + include: { + challenge: true, + }, }), await this.prisma.challenge.count(), ] } async findOne(id: number): Promise { - return await this.prisma.challengeAction.findUnique({ where: { id } }) + return await this.prisma.challengeAction.findUnique({ + where: { id }, + include: { + challenge: true, + }, + }) } async update(id: number, updateChallengeActionDto: UpdateChallengeActionDto): Promise { @@ -36,6 +47,8 @@ export class ChallengeActionsService { } async remove(id: number): Promise { - return await this.prisma.challengeAction.delete({ where: { id } }) + return await this.prisma.challengeAction.delete({ + where: { id }, + }) } } diff --git a/server/src/challenge-actions/dto/create-challenge-action.dto.ts b/server/src/challenge-actions/dto/create-challenge-action.dto.ts index 50e0bcc..13c6371 100644 --- a/server/src/challenge-actions/dto/create-challenge-action.dto.ts +++ b/server/src/challenge-actions/dto/create-challenge-action.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty } from "@nestjs/swagger" import { Type } from "class-transformer" -import { IsBoolean, IsInt } from "class-validator" +import { IsBoolean, IsInt, IsOptional } from "class-validator" export class CreateChallengeActionDto { @IsInt() @@ -8,13 +8,15 @@ export class CreateChallengeActionDto { @ApiProperty({ description: "Identifiant du défi rattaché à l'action" }) challengeId: number + @IsOptional() @IsBoolean() @Type(() => Boolean) - @ApiProperty({ description: "Est-ce que le défi est actuellement en train d'être réalisé" }) - active: boolean + @ApiProperty({ description: "Est-ce que le défi est actuellement en train d'être réalisé", default: true }) + active: boolean = true + @IsOptional() @IsBoolean() @Type(() => Boolean) - @ApiProperty({ description: "Est-ce que le défi a été réussi" }) - success: boolean + @ApiProperty({ description: "Est-ce que le défi a été réussi", default: false }) + success: boolean = false } diff --git a/server/src/challenge-actions/entities/challenge-action.entity.ts b/server/src/challenge-actions/entities/challenge-action.entity.ts index 3990d05..2c7c7a3 100644 --- a/server/src/challenge-actions/entities/challenge-action.entity.ts +++ b/server/src/challenge-actions/entities/challenge-action.entity.ts @@ -1,9 +1,13 @@ import { ApiProperty } from "@nestjs/swagger" import { ChallengeAction } from "@prisma/client" +import { ChallengeEntity } from "src/challenges/entities/challenge.entity" export class ChallengeActionEntity implements ChallengeAction { constructor(partial: Partial) { Object.assign(this, partial) + if (this.challenge) { + this.challenge = new ChallengeEntity(this.challenge) + } } @ApiProperty({ description: "Identifiant unique" }) @@ -15,6 +19,9 @@ export class ChallengeActionEntity implements ChallengeAction { @ApiProperty({ description: "Identifiant du défi rattaché à l'action" }) challengeId: number + @ApiProperty({ type: ChallengeEntity, description: "Défi rattaché à l'action", nullable: true }) + challenge?: ChallengeEntity | null + @ApiProperty({ description: "Est-ce que le défi est actuellement en train d'être réalisé" }) active: boolean