feature/refactorizacion-tabla-sector
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
export interface Sector {
|
||||
id: number;
|
||||
key: string;
|
||||
description: string;
|
||||
authorized: boolean;
|
||||
company_id: number;
|
||||
tenant_id: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface SectorListResponse {
|
||||
@@ -18,18 +21,20 @@ export interface SectorListResponse {
|
||||
export async function getSectors(
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
companyId: number,
|
||||
search?: string
|
||||
): Promise<SectorListResponse> {
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString()
|
||||
page_size: pageSize.toString(),
|
||||
company_id: companyId.toString()
|
||||
});
|
||||
|
||||
if (search) {
|
||||
params.append('search', search);
|
||||
params.append('key', search);
|
||||
}
|
||||
|
||||
const response = await api.get<SectorListResponse>(`/v1/public/reference_data/sectors/?${params.toString()}`);
|
||||
const response = await api.get<SectorListResponse>(`/v1/a76/sectors/?${params.toString()}`);
|
||||
if (!response.data) throw new Error('Error fetching sectors');
|
||||
return response.data;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
/**
|
||||
* API Client para Sectors
|
||||
* Gestiona las operaciones CRUD para los sectores
|
||||
* API Client para Sectors (a76 — tenant-scoped)
|
||||
*/
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export interface Sector {
|
||||
id: number;
|
||||
key: string;
|
||||
description: string;
|
||||
authorized: number;
|
||||
authorized: boolean;
|
||||
company_id: number;
|
||||
tenant_id: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface SectorListResponse {
|
||||
@@ -20,60 +24,45 @@ export interface SectorListResponse {
|
||||
export interface CreateSectorData {
|
||||
key: string;
|
||||
description: string;
|
||||
authorized: number;
|
||||
authorized: boolean;
|
||||
}
|
||||
|
||||
export interface UpdateSectorData {
|
||||
key?: string;
|
||||
description?: string;
|
||||
authorized?: number;
|
||||
authorized?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* API para Sectors
|
||||
*/
|
||||
export const sectorsApi = {
|
||||
/**
|
||||
* Lista todos los sectores con paginación
|
||||
* @param page - Número de página (por defecto 1)
|
||||
* @param pageSize - Tamaño de página (por defecto 50)
|
||||
*/
|
||||
list: (page = 1, pageSize = 50) =>
|
||||
api.get<SectorListResponse>(
|
||||
// CORREGIDO: Slash antes del '?'
|
||||
`/v1/public/reference_data/sectors/?page=${page}&page_size=${pageSize}`
|
||||
),
|
||||
list: (page = 1, pageSize = 50, companyId: number, search?: string) => {
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
company_id: companyId.toString()
|
||||
});
|
||||
if (search) params.append('key', search);
|
||||
return api.get<SectorListResponse>(`/v1/a76/sectors/?${params.toString()}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* Obtiene un sector por key
|
||||
* @param key - Clave del sector
|
||||
*/
|
||||
get: (key: string) =>
|
||||
// CORREGIDO: Slash final
|
||||
api.get<Sector>(`/v1/public/reference_data/sectors/${key}/`),
|
||||
get: (id: number, companyId: number) =>
|
||||
api.get<Sector>(`/v1/a76/sectors/${id}/?company_id=${companyId}`),
|
||||
|
||||
/**
|
||||
* Crea un nuevo sector
|
||||
* @param data - Datos del sector a crear
|
||||
*/
|
||||
create: (data: CreateSectorData) =>
|
||||
// CORREGIDO: Slash final
|
||||
api.post<Sector>('/v1/public/reference_data/sectors/', data),
|
||||
getByKey: (key: string, companyId: number) => {
|
||||
const params = new URLSearchParams({
|
||||
page: '1',
|
||||
page_size: '1',
|
||||
company_id: companyId.toString(),
|
||||
key
|
||||
});
|
||||
return api.get<SectorListResponse>(`/v1/a76/sectors/?${params.toString()}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* Actualiza un sector existente
|
||||
* @param key - Clave del sector a actualizar
|
||||
* @param data - Datos a actualizar
|
||||
*/
|
||||
update: (key: string, data: UpdateSectorData) =>
|
||||
// CORREGIDO: Slash final después de la variable
|
||||
api.put<Sector>(`/v1/public/reference_data/sectors/${key}/`, data),
|
||||
create: (data: CreateSectorData, companyId: number) =>
|
||||
api.post<Sector>(`/v1/a76/sectors/?company_id=${companyId}`, data),
|
||||
|
||||
/**
|
||||
* Elimina un sector
|
||||
* @param key - Clave del sector a eliminar
|
||||
*/
|
||||
delete: (key: string) =>
|
||||
// CORREGIDO: Slash final después de la variable
|
||||
api.delete(`/v1/public/reference_data/sectors/${key}/`)
|
||||
};
|
||||
update: (id: number, data: UpdateSectorData, companyId: number) =>
|
||||
api.put<Sector>(`/v1/a76/sectors/${id}/?company_id=${companyId}`, data),
|
||||
|
||||
delete: (id: number, companyId: number) =>
|
||||
api.delete(`/v1/a76/sectors/${id}/?company_id=${companyId}`)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user