feature/catalogo-equivalencias
This commit is contained in:
@@ -1,43 +1,44 @@
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
export interface Equivalency {
|
||||
export interface EquivalencyItem {
|
||||
id: number;
|
||||
fraccion_mex: string;
|
||||
fraccion_us: string;
|
||||
description?: string;
|
||||
original_field: string; // from_unit_code
|
||||
external_field: string; // to_unit_code
|
||||
conversion_factor: number | null;
|
||||
equivalency_id: number;
|
||||
tenant_id: number;
|
||||
company_id: number;
|
||||
created_at: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface EquivalencyCreate {
|
||||
fraccion_mex: string;
|
||||
fraccion_us: string;
|
||||
description?: string;
|
||||
export interface EquivalencyItemCreate {
|
||||
original_field: string;
|
||||
external_field: string;
|
||||
conversion_factor: number;
|
||||
}
|
||||
|
||||
export interface EquivalencyUpdate {
|
||||
fraccion_mex?: string;
|
||||
fraccion_us?: string;
|
||||
description?: string;
|
||||
export interface EquivalencyItemUpdate {
|
||||
original_field?: string;
|
||||
external_field?: string;
|
||||
conversion_factor?: number | null;
|
||||
}
|
||||
|
||||
export interface EquivalencyListResponse {
|
||||
items: Equivalency[];
|
||||
export interface EquivalencyItemListResponse {
|
||||
items: EquivalencyItem[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
export async function getEquivalencies(
|
||||
export async function getEquivalencyItems(
|
||||
page: number = 1,
|
||||
pageSize: number = 50,
|
||||
companyId: number,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ApiResponse<EquivalencyListResponse>> {
|
||||
) : Promise<ApiResponse<EquivalencyItemListResponse>> {
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
@@ -45,28 +46,31 @@ export async function getEquivalencies(
|
||||
...filters
|
||||
});
|
||||
|
||||
return await api.get(`/v1/a76/equivalencies/?${params.toString()}`);
|
||||
return await api.get(`/v1/a76/equivalencies/items/?${params.toString()}`);
|
||||
}
|
||||
|
||||
export async function getEquivalency(id: number, companyId: number): Promise<ApiResponse<Equivalency>> {
|
||||
return await api.get(`/v1/a76/equivalencies/${id}/?company_id=${companyId}`);
|
||||
}
|
||||
|
||||
export async function createEquivalency(
|
||||
data: EquivalencyCreate,
|
||||
export async function getEquivalencyItem(
|
||||
id: number,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<Equivalency>> {
|
||||
return await api.post(`/v1/a76/equivalencies/?company_id=${companyId}`, data);
|
||||
): Promise<ApiResponse<EquivalencyItem>> {
|
||||
return await api.get(`/v1/a76/equivalencies/items/${id}/?company_id=${companyId}`);
|
||||
}
|
||||
|
||||
export async function updateEquivalency(
|
||||
id: number,
|
||||
data: EquivalencyUpdate,
|
||||
export async function createEquivalencyItem(
|
||||
data: EquivalencyItemCreate,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<Equivalency>> {
|
||||
return await api.put(`/v1/a76/equivalencies/${id}/?company_id=${companyId}`, data);
|
||||
): Promise<ApiResponse<EquivalencyItem>> {
|
||||
return await api.post(`/v1/a76/equivalencies/items/?company_id=${companyId}`, data);
|
||||
}
|
||||
|
||||
export async function deleteEquivalency(id: number, companyId: number): Promise<ApiResponse<void>> {
|
||||
return await api.delete(`/v1/a76/equivalencies/${id}/?company_id=${companyId}`);
|
||||
export async function updateEquivalencyItem(
|
||||
id: number,
|
||||
data: EquivalencyItemUpdate,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<EquivalencyItem>> {
|
||||
return await api.put(`/v1/a76/equivalencies/items/${id}/?company_id=${companyId}`, data);
|
||||
}
|
||||
|
||||
export async function deleteEquivalencyItem(id: number, companyId: number): Promise<ApiResponse<void>> {
|
||||
return await api.delete(`/v1/a76/equivalencies/items/${id}?company_id=${companyId}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user