Ajout filtres actions de défi
This commit is contained in:
parent
c82d39c009
commit
d902e05fdd
@ -8,6 +8,7 @@ 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 {
|
||||||
@ -32,8 +33,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): Promise<PaginateOutputDto<ChallengeActionEntity>> {
|
async findAll(@Query() queryPagination: QueryPaginationDto, @Query() filterChallengeActions: FilterChallengeActionsDto): Promise<PaginateOutputDto<ChallengeActionEntity>> {
|
||||||
const [challengeActions, total] = await this.challengeActionsService.findAll(queryPagination)
|
const [challengeActions, total] = await this.challengeActionsService.findAll(queryPagination, filterChallengeActions)
|
||||||
return paginateOutput<ChallengeActionEntity>(challengeActions.map(challengeAction => new ChallengeActionEntity(challengeAction)), total, queryPagination)
|
return paginateOutput<ChallengeActionEntity>(challengeActions.map(challengeAction => new ChallengeActionEntity(challengeAction)), total, queryPagination)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ 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 {
|
||||||
@ -18,10 +19,12 @@ export class ChallengeActionsService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(queryPagination?: QueryPaginationDto): Promise<[ChallengeAction[], number]> {
|
async findAll(queryPagination: QueryPaginationDto, filterChallengeActions: FilterChallengeActionsDto): 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: {
|
include: {
|
||||||
challenge: true,
|
challenge: true,
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
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, IsOptional } from "class-validator"
|
||||||
|
import { BooleanTransform } from "src/common/utils/transform.utils"
|
||||||
|
|
||||||
export class CreateChallengeActionDto {
|
export class CreateChallengeActionDto {
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@ -10,13 +11,13 @@ export class CreateChallengeActionDto {
|
|||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@Type(() => Boolean)
|
@BooleanTransform()
|
||||||
@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é", default: true })
|
||||||
active: boolean = true
|
active: boolean = true
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@Type(() => Boolean)
|
@BooleanTransform()
|
||||||
@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", default: false })
|
||||||
success: boolean = false
|
success: boolean = false
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
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
|
||||||
|
}
|
9
server/src/common/utils/transform.utils.ts
Normal file
9
server/src/common/utils/transform.utils.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
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…
Reference in New Issue
Block a user