import { Request , Response } from "express" ; import { PrismaClient } from '@prisma/client' ; const prisma = new PrismaClient ( ) ; const getRandomId = ( count , cache ) => { let res = Math . floor ( Math . random ( ) * Math . floor ( count ) + 1 ) ; while ( res == cache ) { res = Math . floor ( Math . random ( ) * Math . floor ( count ) + 1 ) ; } return res ; } ; const randomCat = async ( cache , req , res ) => { let id = getRandomId ( await prisma . cat . count ( ) , cache ) ; console . log ( cache , id ) ; res . send ( await prisma . cat . findUnique ( { where : { id } } ) ) ; return id ; } ; const idCat = async ( req , res ) => { const id = Number ( req . params . id ) ; if ( id > await prisma . cat . count ( ) || id < 1 ) { res . sendStatus ( 400 ) ; return ; } res . send ( await prisma . cat . findUnique ( { where : { id } } ) ) ; } ; const root = async ( req , res ) => { res . sendStatus ( 400 ) ; } ; export { randomCat , idCat , root } ;