From 72519047b9ba17f465c41177e109adcfb1db266c Mon Sep 17 00:00:00 2001 From: Adeosun Oluwaseyi Date: Thu, 15 Aug 2024 21:44:31 +0100 Subject: [PATCH] fix: update documentation --- src/controllers/planController.ts | 285 ++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) diff --git a/src/controllers/planController.ts b/src/controllers/planController.ts index 103fa71a..333920ba 100644 --- a/src/controllers/planController.ts +++ b/src/controllers/planController.ts @@ -3,6 +3,79 @@ import { PlanService } from "../services/super-admin-plans"; const planService = new PlanService(); +/** + * @swagger + * tags: + * - name: Plans + * description: Operations related to plans + */ + +/** + * @swagger + * /api/v1/admin/{userId}/current-plan: + * get: + * tags: + * - Plans + * summary: Get the current plan for a user + * description: Retrieve the current active plan for a specific user. + * parameters: + * - in: path + * name: userId + * required: true + * schema: + * type: string + * description: The ID of the user. + * responses: + * 200: + * description: Successfully retrieved the current plan + * content: + * application/json: + * schema: + * type: object + * properties: + * planName: + * type: string + * example: Premium Plan + * planPrice: + * type: number + * example: 99.99 + * features: + * type: string + * example: Unlimited access, 24/7 support + * startDate: + * type: string + * format: date + * example: 2024-08-15 + * renewalDate: + * type: string + * format: date + * example: 2024-09-15 + * status: + * type: string + * example: Active + * 404: + * description: User or subscription not found + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: User or subscription not found + * 500: + * description: Server error + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Server error + * error: + * type: object + */ export const getCurrentPlan = async (req: Request, res: Response) => { const { userId } = req.params; @@ -14,6 +87,69 @@ export const getCurrentPlan = async (req: Request, res: Response) => { } }; +/** + * @swagger + * /api/v1/admin/plans: + * post: + * tags: + * - Plans + * summary: Create a new plan + * description: Create a new plan with the provided details. + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * name: + * type: string + * example: Premium Plan + * price: + * type: number + * example: 99.99 + * features: + * type: string + * example: Unlimited access, 24/7 support + * limitations: + * type: string + * example: Limited to 5 devices + * responses: + * 201: + * description: Plan created successfully + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Plan created successfully + * plan: + * $ref: '#/components/schemas/Plan' + * 400: + * description: Invalid input or plan already exists + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Invalid input or Plan already exists + * 500: + * description: Server error + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Server error + * error: + * type: object + */ export const createPlan = async (req: Request, res: Response) => { const { name, price, features, limitations } = req.body; @@ -38,6 +174,76 @@ export const createPlan = async (req: Request, res: Response) => { } }; +/** + * @swagger + * /api/v1/admin/{userId}/current-plan: + * put: + * tags: + * - Plans + * summary: Update a specific plan + * description: Update the details of a specific plan. + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * description: The ID of the plan to update. + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * name: + * type: string + * example: Premium Plan + * price: + * type: number + * example: 99.99 + * features: + * type: string + * example: Unlimited access, 24/7 support + * limitations: + * type: string + * example: Limited to 5 devices + * responses: + * 200: + * description: Plan updated successfully + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Plan updated successfully + * plan: + * $ref: '#/components/schemas/Plan' + * 400: + * description: Invalid input or plan not found + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Invalid input or Plan not found + * 500: + * description: Server error + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Server error + * error: + * type: object + */ export const updatePlan = async (req: Request, res: Response) => { const { id } = req.params; const updateData = req.body; @@ -55,6 +261,36 @@ export const updatePlan = async (req: Request, res: Response) => { } }; +/** + * @swagger + * /api/v1/admin/plans: + * get: + * tags: + * - Plans + * summary: Compare all plans + * description: Retrieve and compare all available plans. + * responses: + * 200: + * description: Successfully retrieved all plans + * content: + * application/json: + * schema: + * type: array + * items: + * $ref: '#/components/schemas/Plan' + * 500: + * description: Server error + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Server error + * error: + * type: object + */ export const comparePlans = async (req: Request, res: Response) => { try { const plans = await planService.comparePlans(); @@ -64,6 +300,55 @@ export const comparePlans = async (req: Request, res: Response) => { } }; +/** + * @swagger + * /api/v1/admin/{userId}/current-plan: + * delete: + * tags: + * - Plans + * summary: Delete a specific plan + * description: Delete a specific plan if there are no active subscriptions associated with it. + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * description: The ID of the plan to delete. + * responses: + * 200: + * description: Plan deleted successfully + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Plan deleted successfully + * 400: + * description: Plan not found or has active subscriptions + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Plan not found or has active subscriptions + * 500: + * description: Server error + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: string + * example: Server error + * error: + * type: object + */ export const deletePlan = async (req: Request, res: Response) => { const { id } = req.params;