feat: implement sysadmin subscription management and plan usage cycle recalculation tools
This commit is contained in:
@@ -33,6 +33,119 @@ export const getOrganizationsStatus = async (userId: string) => {
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export type RecalculatePlanUsageCycleResult = {
|
||||
userId: string;
|
||||
subscriptionId: string;
|
||||
planId: string;
|
||||
cycleStart: string;
|
||||
cycleEnd: string;
|
||||
appointmentsCount: number;
|
||||
};
|
||||
|
||||
export const recalculatePlanUsageCycle = async (userId: string): Promise<RecalculatePlanUsageCycleResult> => {
|
||||
const res = await sysadminApi.post('/users/recalculate-plan-usage-cycle', { userId });
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export type UserSubscriptionDetails = {
|
||||
userId: string;
|
||||
currentSubscription: {
|
||||
id: string;
|
||||
plan: {
|
||||
id: string;
|
||||
name: string;
|
||||
code: string;
|
||||
price: number;
|
||||
} | null;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
isActive: boolean;
|
||||
mpStatus?: string;
|
||||
billingMonths?: number;
|
||||
pendingPaymentType?: 'extension' | 'upgrade';
|
||||
pendingPaymentPreferenceId?: string;
|
||||
lastPaymentStatus?: string;
|
||||
} | null;
|
||||
payments: {
|
||||
id: string;
|
||||
subscriptionId: string;
|
||||
amount: number;
|
||||
paymentDate: string;
|
||||
paymentMethod?: string;
|
||||
status: string;
|
||||
transactionId?: string;
|
||||
}[];
|
||||
};
|
||||
|
||||
export const getUserSubscriptionDetails = async (userId: string): Promise<UserSubscriptionDetails> => {
|
||||
const res = await sysadminApi.post('/users/subscription-details', { userId });
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export type ExtendUserSubscriptionPayload = {
|
||||
userId: string;
|
||||
mode: 'add_months' | 'set_end_date';
|
||||
months?: 1 | 2;
|
||||
endDate?: string;
|
||||
reason?: string;
|
||||
};
|
||||
|
||||
export type ExtendUserSubscriptionResult = {
|
||||
userId: string;
|
||||
subscriptionId: string;
|
||||
previousEndDate: string;
|
||||
newEndDate: string;
|
||||
paymentId: string;
|
||||
transactionId?: string;
|
||||
};
|
||||
|
||||
export const extendUserSubscription = async (data: ExtendUserSubscriptionPayload): Promise<ExtendUserSubscriptionResult> => {
|
||||
const res = await sysadminApi.post('/users/extend-subscription', data);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export type Plan = {
|
||||
id?: string;
|
||||
_id?: string;
|
||||
name: string;
|
||||
description: string;
|
||||
features: string[];
|
||||
code: string;
|
||||
price: number;
|
||||
annualPrice: number;
|
||||
limitOrganizations: number;
|
||||
limitEmployees: number;
|
||||
limitServices: number;
|
||||
limitAppointments: number;
|
||||
limitClients: number;
|
||||
limitRepeats: number;
|
||||
mailNotifications: boolean;
|
||||
smsNotifications: boolean;
|
||||
wapNotifications: boolean;
|
||||
payments: boolean;
|
||||
bot: boolean;
|
||||
active: boolean;
|
||||
dateLimit: boolean;
|
||||
discount3Months?: number;
|
||||
discount6Months?: number;
|
||||
discount12Months?: number;
|
||||
featured?: boolean;
|
||||
};
|
||||
|
||||
export type UpdatePlanPayload = Partial<Omit<Plan, 'id' | '_id'>> & {
|
||||
planId: string;
|
||||
};
|
||||
|
||||
export const fetchPlans = async (): Promise<Plan[]> => {
|
||||
const res = await sysadminApi.post('/plans/list', {});
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const updatePlan = async (data: UpdatePlanPayload) => {
|
||||
const res = await sysadminApi.post('/plans/update', data);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
// Wap Servers API Calls
|
||||
export const fetchWapServers = async (filters: any) => {
|
||||
const res = await sysadminApi.post('/wap/paginate', filters);
|
||||
|
||||
Reference in New Issue
Block a user