58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { Injectable } from '@nestjs/common'
|
|
import { CreateChallengeDto } from './dto/create-challenge.dto'
|
|
import { UpdateChallengeDto } from './dto/update-challenge.dto'
|
|
import { Challenge } from '@prisma/client'
|
|
import { PrismaService } from 'src/prisma/prisma.service'
|
|
import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
|
|
import { paginate } from 'src/common/utils/pagination.utils'
|
|
|
|
@Injectable()
|
|
export class ChallengesService {
|
|
constructor(private prisma: PrismaService) { }
|
|
|
|
async create(createChallengeDto: CreateChallengeDto): Promise<Challenge> {
|
|
const data = { ...createChallengeDto }
|
|
return await this.prisma.challenge.create({ data: data })
|
|
}
|
|
|
|
async findAll(queryPagination?: QueryPaginationDto): Promise<[Challenge[], number]> {
|
|
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 },
|
|
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 },
|
|
include: {
|
|
action: true,
|
|
}
|
|
})
|
|
}
|
|
}
|