From 630b3443ba027f4ddb95b0cf3b61142f4c7cf3b8 Mon Sep 17 00:00:00 2001 From: Nainah23 <133117208+Nainah23@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:08:03 +0300 Subject: [PATCH] fix: Instantiate the SqueezeService --- src/controllers/SqueezeController.ts | 41 ++++++++++++++++------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/controllers/SqueezeController.ts b/src/controllers/SqueezeController.ts index 402bf391..744d9a3f 100644 --- a/src/controllers/SqueezeController.ts +++ b/src/controllers/SqueezeController.ts @@ -1,8 +1,13 @@ import { Request, Response } from "express"; import { SqueezeService } from "../services"; - class SqueezeController { + private squeezeService: SqueezeService; + + constructor() { + this.squeezeService = new SqueezeService(); + } + /** * @openapi * /api/v1/squeeze-pages: @@ -62,22 +67,22 @@ class SqueezeController { * description: Conflict */ public createSqueeze = async (req: Request, res: Response) => { - try { - const squeezeData = req.body; - const squeeze = await SqueezeService.createSqueeze(squeezeData); - res.status(201).json({ - status: "success", - message: "Squeeze record created successfully.", - data: squeeze, - }); - } catch (error) { - res.status(500).json({ - status: "error", - message: "An error occurred while creating the squeeze record.", - error: error.message, - }); - } - }; + try { + const squeezeData = req.body; + const squeeze = await this.squeezeService.createSqueeze(squeezeData); // Use the instance method + res.status(201).json({ + status: "success", + message: "Squeeze record created successfully.", + data: squeeze, + }); + } catch (error) { + res.status(500).json({ + status: "error", + message: "An error occurred while creating the squeeze record.", + error: error.message, + }); + } + }; } -export { SqueezeController }; \ No newline at end of file +export { SqueezeController };