import { NotFoundException } from '@nestjs/common' ; import { Injectable } from '@nestjs/common' ; import { Cat } from '@prisma/client' ; import { PrismaService } from '../prisma/prisma.service' ; import { CatUpdateDTO } from './cat-update.dto' ; import { CatDTO } from './cat.dto' ; @ Injectable ( ) export class CatService { constructor ( private readonly prisma ) { } async getAll ( name ? ) { if ( name ) { return this . prisma . cat . findMany ( { where : { name } , } ) ; } return this . prisma . cat . findMany ( ) ; } async getOne ( id ) { return this . prisma . cat . findUnique ( { where : { id } , } ) ; } async insertOne ( cat ) { return this . prisma . cat . create ( { data : cat , } ) ; } async updateOne ( id , cat ) { return this . prisma . cat . update ( { data : cat , where : { id } , } ) ; } async deleteOne ( id ) { try { await this . prisma . cat . delete ( { where : { id } } ) ; return { deleted : true } ; } catch ( err ) { return { deleted : false , message : err . message } ; } } }