- Added methods to normalize permissions and roles from API responses. - Implemented a centralized error handling method for authentication errors. - Updated API endpoints for login, registration, and user profile management. - Introduced session refresh functionality to retrieve user roles and permissions. feat(catalog): improve companies and units management with permissions and filters - Integrated permission checks for creating, updating, and deleting companies. - Added user role and permission checks to the Companies component. - Enhanced the Units component with search and status filters. - Refactored unit creation and update logic to handle validation errors. fix(catalog): update unit measure services and mapping logic - Improved API service methods for fetching, creating, and updating units of measure. - Added mapping functions to convert API responses to internal data structures. - Enhanced error handling in unit measure services. chore(auth): refactor authentication storage utilities - Created utility functions for managing authentication tokens and user data in local storage. - Updated API interceptor to use new storage utility functions for session management. style: clean up code formatting and improve readability across components and services
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import type {
|
|
CreateUnitOfMeasureData,
|
|
UnitOfMeasure,
|
|
UnitOfMeasureApi,
|
|
UpdateUnitOfMeasureData,
|
|
} from '../types/unit-measure.interfaces';
|
|
|
|
const toBoolean = (value: boolean | number | undefined): boolean => {
|
|
if (typeof value === 'boolean') {
|
|
return value;
|
|
}
|
|
|
|
return value === 1;
|
|
};
|
|
|
|
export const mapUnitFromApi = (apiUnit: UnitOfMeasureApi): UnitOfMeasure => ({
|
|
id: apiUnit.id,
|
|
name: apiUnit.name,
|
|
abbreviation: apiUnit.abbreviation,
|
|
is_active: toBoolean(apiUnit.is_active),
|
|
created_at: apiUnit.created_at,
|
|
updated_at: apiUnit.updated_at,
|
|
deleted_at: apiUnit.deleted_at,
|
|
code_sat: apiUnit.code_sat,
|
|
sat_unit: apiUnit.sat_unit,
|
|
});
|
|
|
|
export const mapCreatePayload = (data: CreateUnitOfMeasureData): CreateUnitOfMeasureData => ({
|
|
name: data.name.trim(),
|
|
abbreviation: data.abbreviation?.trim() || undefined,
|
|
code_sat: data.code_sat ?? null,
|
|
is_active: data.is_active ?? true,
|
|
});
|
|
|
|
export const mapUpdatePayload = (data: UpdateUnitOfMeasureData): UpdateUnitOfMeasureData => ({
|
|
name: data.name?.trim(),
|
|
abbreviation: data.abbreviation?.trim() || undefined,
|
|
code_sat: data.code_sat ?? null,
|
|
is_active: data.is_active,
|
|
});
|