diff --git a/server/src/challenge-actions/challenge-actions.service.ts b/server/src/challenge-actions/challenge-actions.service.ts index 095f0ae..e1015a3 100644 --- a/server/src/challenge-actions/challenge-actions.service.ts +++ b/server/src/challenge-actions/challenge-actions.service.ts @@ -15,7 +15,6 @@ export class ChallengeActionsService { const data = { ...createChallengeActionDto, userId: authenticatedUser.id } return await this.prisma.challengeAction.create({ data: data, - include: { challenge: true }, }) } @@ -25,9 +24,6 @@ export class ChallengeActionsService { await this.prisma.challengeAction.findMany({ ...paginate(queryPagination), where: filterChallengeActions, - include: { - challenge: true, - }, }), await this.prisma.challenge.count(), ] @@ -36,9 +32,6 @@ export class ChallengeActionsService { async findOne(id: number): Promise { return await this.prisma.challengeAction.findUnique({ where: { id }, - include: { - challenge: true, - }, }) } diff --git a/server/src/challenge-actions/dto/filter-challenge-action.dto.ts b/server/src/challenge-actions/dto/filter-challenge-action.dto.ts index 7a25b9a..3e66799 100644 --- a/server/src/challenge-actions/dto/filter-challenge-action.dto.ts +++ b/server/src/challenge-actions/dto/filter-challenge-action.dto.ts @@ -7,18 +7,24 @@ export class FilterChallengeActionsDto { @IsOptional() @IsInt() @Type(() => Number) - @ApiProperty({ description: "Identifiant de l'utilisateur⋅rice qui effectue le défi" }) + @ApiProperty({ description: "Identifiant de l'utilisateur⋅rice qui effectue le défi", required: false }) userId?: number + @IsOptional() + @IsInt() + @Type(() => Number) + @ApiProperty({ description: "Identifiant du défi attaché à cette action", required: false }) + challengeId?: number + @IsOptional() @IsBoolean() @BooleanTransform() - @ApiProperty({ description: "Défi en train d'être accompli" }) + @ApiProperty({ description: "Défi en train d'être accompli", required: false }) active?: boolean @IsOptional() @IsBoolean() @BooleanTransform() - @ApiProperty({ description: "Défi réussi" }) + @ApiProperty({ description: "Défi réussi", required: false }) success?: boolean } \ No newline at end of file diff --git a/server/src/challenge-actions/entities/challenge-action.entity.ts b/server/src/challenge-actions/entities/challenge-action.entity.ts index 2c7c7a3..3990d05 100644 --- a/server/src/challenge-actions/entities/challenge-action.entity.ts +++ b/server/src/challenge-actions/entities/challenge-action.entity.ts @@ -1,13 +1,9 @@ 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" }) @@ -19,9 +15,6 @@ 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 diff --git a/server/src/challenges/challenges.service.ts b/server/src/challenges/challenges.service.ts index 6495a9e..4c76b7d 100644 --- a/server/src/challenges/challenges.service.ts +++ b/server/src/challenges/challenges.service.ts @@ -19,23 +19,39 @@ export class ChallengesService { return [ await this.prisma.challenge.findMany({ ...paginate(queryPagination), + include: { + action: true, + } }), await this.prisma.challenge.count(), ] } async findOne(id: number): Promise { - return await this.prisma.challenge.findUnique({ where: { id } }) + return await this.prisma.challenge.findUnique({ + where: { id }, + include: { + action: true, + } + }) } async update(id: number, updateChallengeDto: UpdateChallengeDto): Promise { return await this.prisma.challenge.update({ where: { id }, data: updateChallengeDto, + include: { + action: true, + } }) } async remove(id: number): Promise { - return await this.prisma.challenge.delete({ where: { id } }) + return await this.prisma.challenge.delete({ + where: { id }, + include: { + action: true, + } + }) } } diff --git a/server/src/challenges/entities/challenge.entity.ts b/server/src/challenges/entities/challenge.entity.ts index e5d3f3d..fb9a80e 100644 --- a/server/src/challenges/entities/challenge.entity.ts +++ b/server/src/challenges/entities/challenge.entity.ts @@ -1,9 +1,13 @@ import { ApiProperty } from "@nestjs/swagger" import { Challenge } from "@prisma/client" +import { IsOptional } from "class-validator" +import { ChallengeActionEntity } from "src/challenge-actions/entities/challenge-action.entity" export class ChallengeEntity implements Challenge { constructor(partial: Partial) { Object.assign(this, partial) + if (this.action) + this.action = new ChallengeActionEntity(this.action) } @ApiProperty({ description: "Identifiant unique" }) @@ -17,4 +21,8 @@ export class ChallengeEntity implements Challenge { @ApiProperty({ description: "Récompense en nombre de points en cas de réussite du challenger" }) reward: number + + @IsOptional() + @ApiProperty({ description: "Action réalisée sur ce défi" }) + action?: ChallengeActionEntity }