import { Injectable } from '@nestjs/common' import { Todo, Prisma } from '@prisma/client' import { PrismaService } from 'src/prisma.service' import { TodoDTO } from './dtos/todo.dto' @Injectable() export class TodoService { todo: any constructor(private prismaService: PrismaService) {} //참고: https://intrepidgeeks.com/tutorial/05-instagram-clone-code-5-user-summary //전체조회 async count(sql: any): Promise { return this.prismaService.todo.count() } async fetchAll(sql: any): Promise { return this.prismaService.todo.findMany(sql) } //단일 조회 async fetchOne(id: number): Promise { return this.prismaService.todo.findUnique({ where: { id: Number(id) } }) } //단일 삭제 async remove(id: number): Promise { return this.prismaService.todo.delete({ where: { id: Number(id) } }) } //단일 추가 async add(data: Todo): Promise { return this.prismaService.todo.create({ data: data }) } //단일 수정 async update(id: number, data: TodoDTO): Promise { return this.prismaService.todo.update({ where: { id: Number(id) }, data: data }) } }