186 lines
5.1 KiB
TypeScript
186 lines
5.1 KiB
TypeScript
import axios from 'axios';
|
|
|
|
export const sysadminApi = axios.create({
|
|
baseURL: 'http://localhost:3002',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
// User API Calls
|
|
export const fetchUsers = async (filters: any) => {
|
|
const res = await sysadminApi.post('/users/paginate', filters);
|
|
return res.data;
|
|
};
|
|
|
|
export const updateUserProfile = async (data: any) => {
|
|
const res = await sysadminApi.post('/users/update', data);
|
|
return res.data;
|
|
};
|
|
|
|
export const setVerifiedStatus = async (userId: string, isVerified: boolean) => {
|
|
const res = await sysadminApi.post('/users/set-verified', { userId, isVerified });
|
|
return res.data;
|
|
};
|
|
|
|
export const deleteUser = async (userId: string) => {
|
|
const res = await sysadminApi.post('/users/delete', { userId });
|
|
return res.data;
|
|
};
|
|
|
|
export const getOrganizationsStatus = async (userId: string) => {
|
|
const res = await sysadminApi.post('/users/organizations-status', { userId });
|
|
return res.data;
|
|
};
|
|
|
|
export type RecalculatePlanUsageCycleResult = {
|
|
userId: string;
|
|
subscriptionId: string;
|
|
planId: string;
|
|
cycleStart: string;
|
|
cycleEnd: string;
|
|
organizationsCount: number;
|
|
employeesCount: number;
|
|
servicesCount: number;
|
|
clientsCount: number;
|
|
repeatsCount: number;
|
|
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);
|
|
return res.data;
|
|
};
|
|
|
|
// Companies API Calls
|
|
export const fetchCompanies = async (filters: any) => {
|
|
const res = await sysadminApi.post('/companies/paginate', filters);
|
|
return res.data;
|
|
};
|
|
|
|
export const updateCompany = async (data: any) => {
|
|
const res = await sysadminApi.post('/companies/update', data);
|
|
return res.data;
|
|
};
|
|
|
|
export const setCompanyBanned = async (id: string, banned: boolean) => {
|
|
const res = await sysadminApi.post('/companies/set-banned', { id, banned });
|
|
return res.data;
|
|
};
|
|
|
|
// Services API Calls
|
|
export const fetchServices = async (filters: any) => {
|
|
const res = await sysadminApi.post('/services/paginate', filters);
|
|
return res.data;
|
|
};
|
|
|
|
export const setServiceBanned = async (id: string, banned: boolean) => {
|
|
const res = await sysadminApi.post('/services/set-banned', { id, banned });
|
|
return res.data;
|
|
};
|