74 lines
2.5 KiB
TypeScript
74 lines
2.5 KiB
TypeScript
import { apiClient } from './client';
|
|
|
|
export interface Cartera {
|
|
id: string;
|
|
supervisorUserId: string | null;
|
|
auxiliarUserId: string | null;
|
|
parentId: string | null;
|
|
nombre: string;
|
|
descripcion: string | null;
|
|
createdAt: string;
|
|
entidadesCount: number;
|
|
subcarterasCount: number;
|
|
}
|
|
|
|
export interface SupervisorOption {
|
|
userId: string;
|
|
nombre: string;
|
|
email: string;
|
|
}
|
|
|
|
export async function getCarteras(): Promise<{ data: Cartera[] }> {
|
|
const { data } = await apiClient.get('/carteras');
|
|
return data;
|
|
}
|
|
|
|
export async function getSupervisores(): Promise<{ data: SupervisorOption[] }> {
|
|
const { data } = await apiClient.get('/carteras/supervisores');
|
|
return data;
|
|
}
|
|
|
|
export async function createCartera(payload: { nombre: string; descripcion?: string; supervisorUserId?: string }): Promise<Cartera> {
|
|
const { data } = await apiClient.post('/carteras', payload);
|
|
return data;
|
|
}
|
|
|
|
export async function updateCartera(id: string, payload: { nombre?: string; descripcion?: string }): Promise<Cartera> {
|
|
const { data } = await apiClient.put(`/carteras/${id}`, payload);
|
|
return data;
|
|
}
|
|
|
|
export async function deleteCartera(id: string): Promise<void> {
|
|
await apiClient.delete(`/carteras/${id}`);
|
|
}
|
|
|
|
export async function getCarteraEntidades(id: string): Promise<{ data: string[] }> {
|
|
const { data } = await apiClient.get(`/carteras/${id}/entidades`);
|
|
return data;
|
|
}
|
|
|
|
export async function addEntidadToCartera(carteraId: string, entidadId: string): Promise<void> {
|
|
await apiClient.post(`/carteras/${carteraId}/entidades`, { entidadId });
|
|
}
|
|
|
|
export async function removeEntidadFromCartera(carteraId: string, entidadId: string): Promise<void> {
|
|
await apiClient.delete(`/carteras/${carteraId}/entidades/${entidadId}`);
|
|
}
|
|
|
|
// Subcarteras
|
|
export async function getSubcarteras(carteraId: string): Promise<{ data: Cartera[] }> {
|
|
const { data } = await apiClient.get(`/carteras/${carteraId}/subcarteras`);
|
|
return data;
|
|
}
|
|
|
|
export async function createSubcartera(carteraId: string, payload: { nombre: string; descripcion?: string; auxiliarUserId: string }): Promise<Cartera> {
|
|
const { data } = await apiClient.post(`/carteras/${carteraId}/subcarteras`, payload);
|
|
return data;
|
|
}
|
|
|
|
// Auxiliares del supervisor (for subcartera assignment)
|
|
export async function getAuxiliaresDelSupervisor(supervisorId: string): Promise<{ data: Array<{ auxiliarUserId: string }> }> {
|
|
const { data } = await apiClient.get(`/carteras/${supervisorId}/auxiliares-disponibles`);
|
|
return data;
|
|
}
|