Compare commits
No commits in common. "d902e05fdd6709fa5116ca4b1c80d9ea4812a9ea" and "572a04130f065db52d9167ce8c0c68727dd993ad" have entirely different histories.
d902e05fdd
...
572a04130f
@ -8,7 +8,6 @@ import { ApiOkResponsePaginated, paginateOutput } from 'src/common/utils/paginat
|
|||||||
import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
|
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'
|
|
||||||
|
|
||||||
@Controller('challenge-actions')
|
@Controller('challenge-actions')
|
||||||
export class ChallengeActionsController {
|
export class ChallengeActionsController {
|
||||||
@ -33,8 +32,8 @@ export class ChallengeActionsController {
|
|||||||
@ApiOkResponsePaginated(ChallengeActionEntity)
|
@ApiOkResponsePaginated(ChallengeActionEntity)
|
||||||
@ApiUnauthorizedResponse({ description: "Non authentifié⋅e" })
|
@ApiUnauthorizedResponse({ description: "Non authentifié⋅e" })
|
||||||
@ApiForbiddenResponse({ description: "Permission refusée" })
|
@ApiForbiddenResponse({ description: "Permission refusée" })
|
||||||
async findAll(@Query() queryPagination: QueryPaginationDto, @Query() filterChallengeActions: FilterChallengeActionsDto): Promise<PaginateOutputDto<ChallengeActionEntity>> {
|
async findAll(@Query() queryPagination?: QueryPaginationDto): Promise<PaginateOutputDto<ChallengeActionEntity>> {
|
||||||
const [challengeActions, total] = await this.challengeActionsService.findAll(queryPagination, filterChallengeActions)
|
const [challengeActions, total] = await this.challengeActionsService.findAll(queryPagination)
|
||||||
return paginateOutput<ChallengeActionEntity>(challengeActions.map(challengeAction => new ChallengeActionEntity(challengeAction)), total, queryPagination)
|
return paginateOutput<ChallengeActionEntity>(challengeActions.map(challengeAction => new ChallengeActionEntity(challengeAction)), total, queryPagination)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import { ChallengeAction, User } from '@prisma/client'
|
|||||||
import { PrismaService } from 'src/prisma/prisma.service'
|
import { PrismaService } from 'src/prisma/prisma.service'
|
||||||
import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
|
import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
|
||||||
import { paginate } from 'src/common/utils/pagination.utils'
|
import { paginate } from 'src/common/utils/pagination.utils'
|
||||||
import { FilterChallengeActionsDto } from './dto/filter-challenge-action.dto'
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ChallengeActionsService {
|
export class ChallengeActionsService {
|
||||||
@ -13,33 +12,20 @@ export class ChallengeActionsService {
|
|||||||
|
|
||||||
async create(authenticatedUser: User, createChallengeActionDto: CreateChallengeActionDto): Promise<ChallengeAction> {
|
async create(authenticatedUser: User, createChallengeActionDto: CreateChallengeActionDto): Promise<ChallengeAction> {
|
||||||
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 },
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(queryPagination: QueryPaginationDto, filterChallengeActions: FilterChallengeActionsDto): Promise<[ChallengeAction[], number]> {
|
async findAll(queryPagination?: QueryPaginationDto): Promise<[ChallengeAction[], number]> {
|
||||||
console.log(filterChallengeActions)
|
|
||||||
return [
|
return [
|
||||||
await this.prisma.challengeAction.findMany({
|
await this.prisma.challengeAction.findMany({
|
||||||
...paginate(queryPagination),
|
...paginate(queryPagination),
|
||||||
where: filterChallengeActions,
|
|
||||||
include: {
|
|
||||||
challenge: true,
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
await this.prisma.challenge.count(),
|
await this.prisma.challenge.count(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: number, updateChallengeActionDto: UpdateChallengeActionDto): Promise<ChallengeAction> {
|
async update(id: number, updateChallengeActionDto: UpdateChallengeActionDto): Promise<ChallengeAction> {
|
||||||
@ -50,8 +36,6 @@ export class ChallengeActionsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: number): Promise<ChallengeAction> {
|
async remove(id: number): Promise<ChallengeAction> {
|
||||||
return await this.prisma.challengeAction.delete({
|
return await this.prisma.challengeAction.delete({ where: { id } })
|
||||||
where: { id },
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { ApiProperty } from "@nestjs/swagger"
|
import { ApiProperty } from "@nestjs/swagger"
|
||||||
import { Type } from "class-transformer"
|
import { Type } from "class-transformer"
|
||||||
import { IsBoolean, IsInt, IsOptional } from "class-validator"
|
import { IsBoolean, IsInt } from "class-validator"
|
||||||
import { BooleanTransform } from "src/common/utils/transform.utils"
|
|
||||||
|
|
||||||
export class CreateChallengeActionDto {
|
export class CreateChallengeActionDto {
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@ -9,15 +8,13 @@ export class CreateChallengeActionDto {
|
|||||||
@ApiProperty({ description: "Identifiant du défi rattaché à l'action" })
|
@ApiProperty({ description: "Identifiant du défi rattaché à l'action" })
|
||||||
challengeId: number
|
challengeId: number
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@BooleanTransform()
|
@Type(() => Boolean)
|
||||||
@ApiProperty({ description: "Est-ce que le défi est actuellement en train d'être réalisé", default: true })
|
@ApiProperty({ description: "Est-ce que le défi est actuellement en train d'être réalisé" })
|
||||||
active: boolean = true
|
active: boolean
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@BooleanTransform()
|
@Type(() => Boolean)
|
||||||
@ApiProperty({ description: "Est-ce que le défi a été réussi", default: false })
|
@ApiProperty({ description: "Est-ce que le défi a été réussi" })
|
||||||
success: boolean = false
|
success: boolean
|
||||||
}
|
}
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
import { ApiProperty } from "@nestjs/swagger"
|
|
||||||
import { Type } from "class-transformer"
|
|
||||||
import { IsBoolean, IsInt, IsOptional } from "class-validator"
|
|
||||||
import { BooleanTransform } from "src/common/utils/transform.utils"
|
|
||||||
|
|
||||||
export class FilterChallengeActionsDto {
|
|
||||||
@IsOptional()
|
|
||||||
@IsInt()
|
|
||||||
@Type(() => Number)
|
|
||||||
@ApiProperty({ description: "Identifiant de l'utilisateur⋅rice qui effectue le défi" })
|
|
||||||
userId?: number
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
@BooleanTransform()
|
|
||||||
@ApiProperty({ description: "Défi en train d'être accompli" })
|
|
||||||
active?: boolean
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
@BooleanTransform()
|
|
||||||
@ApiProperty({ description: "Défi réussi" })
|
|
||||||
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
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
import { Transform, TransformOptions } from "class-transformer"
|
|
||||||
|
|
||||||
export function BooleanTransform (options?: TransformOptions): PropertyDecorator {
|
|
||||||
return Transform(({ value }) => {
|
|
||||||
if (value.toString().toLowerCase() === "false")
|
|
||||||
return false
|
|
||||||
return Boolean(value)
|
|
||||||
}, options)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user