feat: implement sysadmin subscription management and plan usage cycle recalculation tools
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { Request, Response } from "express";
|
||||
import { PlansService } from "../services/plans.service";
|
||||
import { SysAdminUpdatePlanParams } from "../models/Plans.Model";
|
||||
|
||||
const plansService = new PlansService();
|
||||
|
||||
export class PlansController {
|
||||
public listPlans = async (_req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const plans = await plansService.listPlans();
|
||||
res.json(plans);
|
||||
} catch (error: any) {
|
||||
console.error("Error listing plans:", error?.response?.data || error);
|
||||
res.status(500).json(error?.response?.data || { success: false, message: "Internal Server Error" });
|
||||
}
|
||||
};
|
||||
|
||||
public updatePlan = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const data: SysAdminUpdatePlanParams = req.body;
|
||||
const result = await plansService.updatePlan(data);
|
||||
res.json(result);
|
||||
} catch (error: any) {
|
||||
console.error("Error updating plan:", error?.response?.data || error);
|
||||
res.status(500).json(error?.response?.data || { success: false, message: "Internal Server Error" });
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import {
|
||||
SysAdminSetVerifiedParams,
|
||||
SysAdminDeleteUserParams,
|
||||
SysAdminOrganizationsStatusParams,
|
||||
SysAdminRecalculatePlanUsageCycleParams,
|
||||
SysAdminExtendUserSubscriptionParams,
|
||||
SysAdminUserSubscriptionDetailsParams,
|
||||
} from "../models/Users.Model";
|
||||
|
||||
const usersService = new UsersService();
|
||||
@@ -65,4 +68,37 @@ export class UsersController {
|
||||
res.status(500).json(error?.response?.data || { success: false, message: "Internal Server Error" });
|
||||
}
|
||||
};
|
||||
|
||||
public recalculatePlanUsageCycle = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const data: SysAdminRecalculatePlanUsageCycleParams = req.body;
|
||||
const result = await usersService.recalculatePlanUsageCycle(data);
|
||||
res.json(result);
|
||||
} catch (error: any) {
|
||||
console.error("Error recalculating plan usage cycle:", error?.response?.data || error);
|
||||
res.status(500).json(error?.response?.data || { success: false, message: "Internal Server Error" });
|
||||
}
|
||||
};
|
||||
|
||||
public subscriptionDetails = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const data: SysAdminUserSubscriptionDetailsParams = req.body;
|
||||
const result = await usersService.getSubscriptionDetails(data);
|
||||
res.json(result);
|
||||
} catch (error: any) {
|
||||
console.error("Error fetching subscription details:", error?.response?.data || error);
|
||||
res.status(500).json(error?.response?.data || { success: false, message: "Internal Server Error" });
|
||||
}
|
||||
};
|
||||
|
||||
public extendSubscription = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const data: SysAdminExtendUserSubscriptionParams = req.body;
|
||||
const result = await usersService.extendSubscription(data);
|
||||
res.json(result);
|
||||
} catch (error: any) {
|
||||
console.error("Error extending subscription:", error?.response?.data || error);
|
||||
res.status(500).json(error?.response?.data || { success: false, message: "Internal Server Error" });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user