423 lines
11 KiB
TypeScript
423 lines
11 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 FinalizeUserSubscriptionPayload = {
|
|
userId: string;
|
|
reason?: string;
|
|
};
|
|
|
|
export type FinalizeUserSubscriptionResult = {
|
|
userId: string;
|
|
subscriptionId: string;
|
|
previousEndDate: string;
|
|
newEndDate: string;
|
|
};
|
|
|
|
export const finalizeUserSubscription = async (data: FinalizeUserSubscriptionPayload): Promise<FinalizeUserSubscriptionResult> => {
|
|
const res = await sysadminApi.post('/users/finalize-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;
|
|
};
|
|
|
|
export type WapServer = {
|
|
id?: string;
|
|
_id?: string;
|
|
name?: string;
|
|
description?: string;
|
|
ipv4: string;
|
|
ipv6?: string;
|
|
countBots: number;
|
|
maxBots: number;
|
|
port: number;
|
|
active: boolean;
|
|
};
|
|
|
|
export type UpdateWapServerPayload = {
|
|
serverId: string;
|
|
name?: string;
|
|
ipv4?: string;
|
|
port?: number;
|
|
maxBots?: number;
|
|
active?: boolean;
|
|
};
|
|
|
|
export type CreateWapServerPayload = {
|
|
name: string;
|
|
ipv4: string;
|
|
port: number;
|
|
maxBots: number;
|
|
ipv6?: string;
|
|
description?: string;
|
|
active?: boolean;
|
|
};
|
|
|
|
export const createWapServer = async (data: CreateWapServerPayload): Promise<WapServer> => {
|
|
const res = await sysadminApi.post('/wap/create', data);
|
|
return res.data;
|
|
};
|
|
|
|
export const updateWapServer = async (data: UpdateWapServerPayload): Promise<WapServer> => {
|
|
const res = await sysadminApi.post('/wap/update', data);
|
|
return res.data;
|
|
};
|
|
|
|
export type WapAssignedOrganization = {
|
|
id: string;
|
|
name?: string;
|
|
};
|
|
|
|
export type WapContainerDto = {
|
|
id?: string;
|
|
name?: string;
|
|
organizationId?: string;
|
|
image?: string;
|
|
state?: string;
|
|
status?: string;
|
|
ports?: unknown[];
|
|
created?: number;
|
|
};
|
|
|
|
export type WapServerAuditResult = {
|
|
serverId: string;
|
|
assignedOrganizations: WapAssignedOrganization[];
|
|
detectedBots: WapContainerDto[];
|
|
validBots: WapContainerDto[];
|
|
ghostBots: WapContainerDto[];
|
|
missingBots: WapAssignedOrganization[];
|
|
expectedCountBots: number;
|
|
storedCountBots: number;
|
|
runtimeCountBots: number;
|
|
countMismatch: boolean;
|
|
};
|
|
|
|
export type WapServerRecalculateCountResult = {
|
|
serverId: string;
|
|
before: number;
|
|
after: number;
|
|
};
|
|
|
|
export type WapServerDeleteResult = {
|
|
serverId: string;
|
|
deleted: true;
|
|
force?: boolean;
|
|
detachedOrganizations?: number;
|
|
deletedRuntimeBots?: number;
|
|
skippedRuntimeBots?: number;
|
|
auditFailed?: boolean;
|
|
auditMessage?: string;
|
|
};
|
|
|
|
export type WapServerDeletePayload = {
|
|
serverId: string;
|
|
force?: boolean;
|
|
};
|
|
|
|
export type WapServerOrganizationActionPayload = {
|
|
serverId: string;
|
|
organizationId: string;
|
|
};
|
|
|
|
export type WapServerQrResult = WapServerOrganizationActionPayload & {
|
|
qr: string;
|
|
};
|
|
|
|
export type WapServerDetachResult = WapServerOrganizationActionPayload & {
|
|
botDeleted: boolean;
|
|
botAlreadyMissing: boolean;
|
|
before: number;
|
|
after: number;
|
|
};
|
|
|
|
export const auditWapServer = async (serverId: string): Promise<WapServerAuditResult> => {
|
|
const res = await sysadminApi.post('/wap/audit', { serverId });
|
|
return res.data;
|
|
};
|
|
|
|
export const recalculateWapServerCount = async (serverId: string): Promise<WapServerRecalculateCountResult> => {
|
|
const res = await sysadminApi.post('/wap/recalculate-count', { serverId });
|
|
return res.data;
|
|
};
|
|
|
|
export const deleteWapServer = async (data: WapServerDeletePayload): Promise<WapServerDeleteResult> => {
|
|
const res = await sysadminApi.post('/wap/delete', data);
|
|
return res.data;
|
|
};
|
|
|
|
export const startWapBot = async (data: WapServerOrganizationActionPayload): Promise<void> => {
|
|
await sysadminApi.post('/wap/bot/start', data);
|
|
};
|
|
|
|
export const stopWapBot = async (data: WapServerOrganizationActionPayload): Promise<void> => {
|
|
await sysadminApi.post('/wap/bot/stop', data);
|
|
};
|
|
|
|
export const restartWapBot = async (data: WapServerOrganizationActionPayload): Promise<void> => {
|
|
await sysadminApi.post('/wap/bot/restart', data);
|
|
};
|
|
|
|
export const getWapBotQr = async (data: WapServerOrganizationActionPayload): Promise<WapServerQrResult> => {
|
|
const res = await sysadminApi.post('/wap/bot/qr', data);
|
|
return res.data;
|
|
};
|
|
|
|
export const deleteWapBot = async (data: WapServerOrganizationActionPayload): Promise<void> => {
|
|
await sysadminApi.post('/wap/bot/delete', data);
|
|
};
|
|
|
|
export const detachWapOrganizationServer = async (data: WapServerOrganizationActionPayload): Promise<WapServerDetachResult> => {
|
|
const res = await sysadminApi.post('/wap/bot/detach', data);
|
|
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;
|
|
};
|
|
|
|
export type OrganizationInsights = {
|
|
organization: {
|
|
id: string;
|
|
name: string;
|
|
slug: string;
|
|
description: string;
|
|
categoryId: number;
|
|
banned: boolean;
|
|
published?: string;
|
|
onboardingStep?: number;
|
|
onboardingCompleted?: boolean;
|
|
};
|
|
owner: {
|
|
id: string;
|
|
firstName?: string;
|
|
lastName?: string;
|
|
email?: string;
|
|
verificated?: boolean;
|
|
phoneCountryCode?: string;
|
|
phoneAreaCode?: string;
|
|
phoneNumber?: string;
|
|
} | null;
|
|
collaborators: {
|
|
id: string;
|
|
userId?: string;
|
|
firstName?: string;
|
|
lastName?: string;
|
|
fullName?: string;
|
|
email?: string;
|
|
roles?: string[];
|
|
removed?: boolean;
|
|
active: boolean;
|
|
avatar?: string;
|
|
}[];
|
|
subscription: {
|
|
id: string;
|
|
startDate: string;
|
|
endDate: string;
|
|
isActive: boolean;
|
|
autoRenew: boolean;
|
|
mpStatus?: string;
|
|
pendingPaymentType?: 'extension' | 'upgrade';
|
|
plan: {
|
|
id: string;
|
|
name: string;
|
|
code: string;
|
|
price: number;
|
|
limitOrganizations: number;
|
|
limitEmployees: number;
|
|
limitServices: number;
|
|
limitAppointments: number;
|
|
limitClients: number;
|
|
} | null;
|
|
} | null;
|
|
stats: {
|
|
employeesCount: number;
|
|
activeEmployeesCount: number;
|
|
servicesCount: number;
|
|
activeServicesCount: number;
|
|
clientsCount: number;
|
|
activeClientsCount: number;
|
|
reservationsLast30Days: number;
|
|
};
|
|
};
|
|
|
|
export const fetchOrganizationInsights = async (companyId: string): Promise<OrganizationInsights> => {
|
|
const res = await sysadminApi.post('/companies/insights', { companyId });
|
|
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;
|
|
};
|