Affiche de l'action attachée à un défi dans le modèle de défi
This commit is contained in:
parent
d902e05fdd
commit
54e002e1f8
@ -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<ChallengeAction> {
|
||||
return await this.prisma.challengeAction.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
challenge: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
@ -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<ChallengeActionEntity>) {
|
||||
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
|
||||
|
||||
|
@ -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<Challenge> {
|
||||
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<Challenge> {
|
||||
return await this.prisma.challenge.update({
|
||||
where: { id },
|
||||
data: updateChallengeDto,
|
||||
include: {
|
||||
action: true,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<Challenge> {
|
||||
return await this.prisma.challenge.delete({ where: { id } })
|
||||
return await this.prisma.challenge.delete({
|
||||
where: { id },
|
||||
include: {
|
||||
action: true,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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<ChallengeEntity>) {
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user