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 }
|
const data = { ...createChallengeActionDto, userId: authenticatedUser.id }
|
||||||
return await this.prisma.challengeAction.create({
|
return await this.prisma.challengeAction.create({
|
||||||
data: data,
|
data: data,
|
||||||
include: { challenge: true },
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,9 +24,6 @@ export class ChallengeActionsService {
|
|||||||
await this.prisma.challengeAction.findMany({
|
await this.prisma.challengeAction.findMany({
|
||||||
...paginate(queryPagination),
|
...paginate(queryPagination),
|
||||||
where: filterChallengeActions,
|
where: filterChallengeActions,
|
||||||
include: {
|
|
||||||
challenge: true,
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
await this.prisma.challenge.count(),
|
await this.prisma.challenge.count(),
|
||||||
]
|
]
|
||||||
@ -36,9 +32,6 @@ export class ChallengeActionsService {
|
|||||||
async findOne(id: number): Promise<ChallengeAction> {
|
async findOne(id: number): Promise<ChallengeAction> {
|
||||||
return await this.prisma.challengeAction.findUnique({
|
return await this.prisma.challengeAction.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
include: {
|
|
||||||
challenge: true,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,18 +7,24 @@ export class FilterChallengeActionsDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@Type(() => Number)
|
@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
|
userId?: number
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsInt()
|
||||||
|
@Type(() => Number)
|
||||||
|
@ApiProperty({ description: "Identifiant du défi attaché à cette action", required: false })
|
||||||
|
challengeId?: number
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@BooleanTransform()
|
@BooleanTransform()
|
||||||
@ApiProperty({ description: "Défi en train d'être accompli" })
|
@ApiProperty({ description: "Défi en train d'être accompli", required: false })
|
||||||
active?: boolean
|
active?: boolean
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@BooleanTransform()
|
@BooleanTransform()
|
||||||
@ApiProperty({ description: "Défi réussi" })
|
@ApiProperty({ description: "Défi réussi", required: false })
|
||||||
success?: boolean
|
success?: boolean
|
||||||
}
|
}
|
@ -1,13 +1,9 @@
|
|||||||
import { ApiProperty } from "@nestjs/swagger"
|
import { ApiProperty } from "@nestjs/swagger"
|
||||||
import { ChallengeAction } from "@prisma/client"
|
import { ChallengeAction } from "@prisma/client"
|
||||||
import { ChallengeEntity } from "src/challenges/entities/challenge.entity"
|
|
||||||
|
|
||||||
export class ChallengeActionEntity implements ChallengeAction {
|
export class ChallengeActionEntity implements ChallengeAction {
|
||||||
constructor(partial: Partial<ChallengeActionEntity>) {
|
constructor(partial: Partial<ChallengeActionEntity>) {
|
||||||
Object.assign(this, partial)
|
Object.assign(this, partial)
|
||||||
if (this.challenge) {
|
|
||||||
this.challenge = new ChallengeEntity(this.challenge)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiProperty({ description: "Identifiant unique" })
|
@ApiProperty({ description: "Identifiant unique" })
|
||||||
@ -19,9 +15,6 @@ export class ChallengeActionEntity implements ChallengeAction {
|
|||||||
@ApiProperty({ description: "Identifiant du défi rattaché à l'action" })
|
@ApiProperty({ description: "Identifiant du défi rattaché à l'action" })
|
||||||
challengeId: number
|
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é" })
|
@ApiProperty({ description: "Est-ce que le défi est actuellement en train d'être réalisé" })
|
||||||
active: boolean
|
active: boolean
|
||||||
|
|
||||||
|
@ -19,23 +19,39 @@ export class ChallengesService {
|
|||||||
return [
|
return [
|
||||||
await this.prisma.challenge.findMany({
|
await this.prisma.challenge.findMany({
|
||||||
...paginate(queryPagination),
|
...paginate(queryPagination),
|
||||||
|
include: {
|
||||||
|
action: true,
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
await this.prisma.challenge.count(),
|
await this.prisma.challenge.count(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: number): Promise<Challenge> {
|
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> {
|
async update(id: number, updateChallengeDto: UpdateChallengeDto): Promise<Challenge> {
|
||||||
return await this.prisma.challenge.update({
|
return await this.prisma.challenge.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: updateChallengeDto,
|
data: updateChallengeDto,
|
||||||
|
include: {
|
||||||
|
action: true,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: number): Promise<Challenge> {
|
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 { ApiProperty } from "@nestjs/swagger"
|
||||||
import { Challenge } from "@prisma/client"
|
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 {
|
export class ChallengeEntity implements Challenge {
|
||||||
constructor(partial: Partial<ChallengeEntity>) {
|
constructor(partial: Partial<ChallengeEntity>) {
|
||||||
Object.assign(this, partial)
|
Object.assign(this, partial)
|
||||||
|
if (this.action)
|
||||||
|
this.action = new ChallengeActionEntity(this.action)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiProperty({ description: "Identifiant unique" })
|
@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" })
|
@ApiProperty({ description: "Récompense en nombre de points en cas de réussite du challenger" })
|
||||||
reward: number
|
reward: number
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@ApiProperty({ description: "Action réalisée sur ce défi" })
|
||||||
|
action?: ChallengeActionEntity
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user