diff --git a/src/controllers/TestimonialsController.ts b/src/controllers/TestimonialsController.ts index 9f1e5592..a1982b36 100644 --- a/src/controllers/TestimonialsController.ts +++ b/src/controllers/TestimonialsController.ts @@ -133,4 +133,43 @@ export default class TestimonialsController { res.status(500).send({ message: error.message }); } } + + // CODE BY TOMILLA OLUWAFEMI + public async getAllTestimonials(req: Request, res: Response) { + try { + const testimonials = await AppDataSource.getRepository(Testimonial).find(); + res.status(200).json({ + message: "Testimonials retrieved successfully", + status_code: 200, + data: testimonials, + }); + } catch (error) { + res.status(500).send({ message: error.message }); + } + } + + public async deleteTestimonial(req: Request, res: Response) { + try { + const { testimonial_id } = req.params; + + const testimonialToDelete = await AppDataSource.getRepository(Testimonial).findOne({ + where: { id: testimonial_id }, + }); + + if (!testimonialToDelete) { + return res + .status(404) + .send({ message: "Testimonial not found", status_code: 404 }); + } + + await AppDataSource.getRepository(Testimonial).remove(testimonialToDelete); + + res.status(200).json({ + message: "Testimonial deleted successfully", + status_code: 200, + }); + } catch (error) { + res.status(500).send({ message: error.message }); + } + } } diff --git a/src/routes/testimonial.ts b/src/routes/testimonial.ts index 127436fe..55cdc57f 100644 --- a/src/routes/testimonial.ts +++ b/src/routes/testimonial.ts @@ -19,4 +19,16 @@ testimonialRoute.get( testimonialController.getTestimonial.bind(testimonialController) ); +// CODE BY TOMILOLA OLUWAFEMI +testimonialRoute.get( + "/testimonials", + authMiddleware, + testimonialController.getAllTestimonials.bind(testimonialController) +); +testimonialRoute.delete( + "/testimonials/:testimonial_id", + authMiddleware, + testimonialController.deleteTestimonial.bind(testimonialController) +); + export { testimonialRoute };