import { NextApiRequest , NextApiResponse } from 'next' ; import catchErrors from '../../middleware/catchErrors' ; import { StatusCodes } from 'http-status-codes' ; import Like , { ILike } from '../models/likes' ; import { APIfeatures } from '../../utils/apiFeatures' ; EXPORTS export { addNewLike , getAllLikes } ; POST function param { NextApiRequest } req param { NextApiResponse } res returns { undefined } const addNewLike = catchErrors ( async ( req , res ) : Promise < void > => { const newLike = await Like . create ( { } ) ; res . status ( StatusCodes . OK ) . json ( { success : true , newLike , } ) ; } ) ; GET function param { NextApiRequest } req param { NextApiResponse } res return { undefined } const getAllLikes = async ( req , res ) : Promise < void > => { const features = new APIfeatures ( Like . find ( { } ) , req . query as { [ key ] : string ; } ) . sort ( ) ; const allLikes = await features . query ; res . status ( StatusCodes . OK ) . json ( { success : true , totalLikes : allLikes . length , likes : allLikes , } ) ; } ;