import { Injectable } from '@nestjs/common' import { CreateChallengeActionDto } from './dto/create-challenge-action.dto' import { UpdateChallengeActionDto } from './dto/update-challenge-action.dto' import { ChallengeAction, User } 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' import { FilterChallengeActionsDto } from './dto/filter-challenge-action.dto' @Injectable() export class ChallengeActionsService { constructor(private prisma: PrismaService) { } async create(authenticatedUser: User, createChallengeActionDto: CreateChallengeActionDto): Promise { const data = { ...createChallengeActionDto, userId: authenticatedUser.id } return await this.prisma.challengeAction.create({ data: data, }) } async findAll(queryPagination: QueryPaginationDto, filterChallengeActions: FilterChallengeActionsDto): Promise<[ChallengeAction[], number]> { console.log(filterChallengeActions) return [ await this.prisma.challengeAction.findMany({ ...paginate(queryPagination), where: filterChallengeActions, }), await this.prisma.challengeAction.count(), ] } async findOne(id: number): Promise { return await this.prisma.challengeAction.findUnique({ where: { id }, }) } async update(id: number, updateChallengeActionDto: UpdateChallengeActionDto): Promise { console.log(updateChallengeActionDto) return await this.prisma.challengeAction.update({ where: { id }, data: updateChallengeActionDto, }) } async remove(id: number): Promise { return await this.prisma.challengeAction.delete({ where: { id }, }) } }