Initial commit - Horux Despachos NL
This commit is contained in:
97
apps/web/lib/api/tenants.ts
Normal file
97
apps/web/lib/api/tenants.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { apiClient } from './client';
|
||||
|
||||
export interface Tenant {
|
||||
id: string;
|
||||
nombre: string;
|
||||
rfc: string;
|
||||
plan: string;
|
||||
databaseName: string;
|
||||
createdAt: string;
|
||||
_count?: {
|
||||
/** Memberships activos (matches el `_count.memberships` que retorna `getAllTenants`). */
|
||||
memberships: number;
|
||||
};
|
||||
}
|
||||
|
||||
export type TenantPlan = 'trial' | 'custom' | 'mi_empresa' | 'mi_empresa_plus' | 'business_control' | 'business_cloud';
|
||||
|
||||
export interface CreateTenantData {
|
||||
nombre: string;
|
||||
rfc: string;
|
||||
plan?: TenantPlan;
|
||||
adminEmail: string;
|
||||
adminNombre: string;
|
||||
amount?: number;
|
||||
/** Solo plan custom: deadline para primer pago (formato ISO YYYY-MM-DD). */
|
||||
firstPaymentDueAt?: string | null;
|
||||
}
|
||||
|
||||
export async function getTenants(): Promise<Tenant[]> {
|
||||
const response = await apiClient.get<Tenant[]>('/tenants');
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getTenant(id: string): Promise<Tenant> {
|
||||
const response = await apiClient.get<Tenant>(`/tenants/${id}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function createTenant(data: CreateTenantData): Promise<Tenant> {
|
||||
const response = await apiClient.post<Tenant>('/tenants', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export interface UpdateTenantData {
|
||||
nombre?: string;
|
||||
rfc?: string;
|
||||
plan?: TenantPlan;
|
||||
active?: boolean;
|
||||
}
|
||||
|
||||
export async function updateTenant(id: string, data: UpdateTenantData): Promise<Tenant> {
|
||||
const response = await apiClient.put<Tenant>(`/tenants/${id}`, data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteTenant(id: string): Promise<void> {
|
||||
await apiClient.delete(`/tenants/${id}`);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Self-serve multi-tenant (memberships del caller)
|
||||
// ============================================================================
|
||||
|
||||
export interface MyTenantDetailed {
|
||||
tenantId: string;
|
||||
nombre: string;
|
||||
rfc: string;
|
||||
plan: string;
|
||||
role: string;
|
||||
isOwner: boolean;
|
||||
trialEndsAt: string | null;
|
||||
subscription: {
|
||||
status: string;
|
||||
plan: string;
|
||||
amount: number;
|
||||
frequency: string;
|
||||
currentPeriodEnd: string | null;
|
||||
pendingPlan: string | null;
|
||||
pendingEffectiveAt: string | null;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export async function getMyTenants(): Promise<MyTenantDetailed[]> {
|
||||
const response = await apiClient.get<MyTenantDetailed[]>('/tenants/mine');
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export interface AddMyTenantData {
|
||||
nombre: string;
|
||||
rfc: string;
|
||||
plan?: 'mi_empresa' | 'mi_empresa_plus' | 'business_control' | 'business_cloud';
|
||||
}
|
||||
|
||||
export async function addMyTenant(data: AddMyTenantData): Promise<{ tenant: Tenant }> {
|
||||
const response = await apiClient.post<{ tenant: Tenant }>('/tenants/mine', data);
|
||||
return response.data;
|
||||
}
|
||||
Reference in New Issue
Block a user