Add PostgreSQL support with SQLite/Postgres database compatibility layer
- Add dbGet/dbAll helper functions for database-agnostic queries - Add toDbBool/convertBooleansForDb for boolean type conversion - Add toDbDate/getNow for timestamp type handling - Add generateId that returns UUID for Postgres, nanoid for SQLite - Update all routes to use compatibility helpers - Add normalizeEvent to return clean number types from Postgres decimal - Add formatPrice utility for consistent price display - Add legal pages admin interface with RichTextEditor - Update carousel images - Add drizzle migration files for PostgreSQL
This commit is contained in:
36
frontend/src/lib/utils.ts
Normal file
36
frontend/src/lib/utils.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Format price - shows decimals only if needed
|
||||
* Uses space as thousands separator (common in Paraguay)
|
||||
* Examples:
|
||||
* 45000 PYG -> "45 000 PYG" (no decimals)
|
||||
* 41.44 PYG -> "41,44 PYG" (with decimals)
|
||||
*/
|
||||
export function formatPrice(price: number, currency: string = 'PYG'): string {
|
||||
const hasDecimals = price % 1 !== 0;
|
||||
|
||||
// Format the integer and decimal parts separately
|
||||
const intPart = Math.floor(Math.abs(price));
|
||||
const decPart = Math.abs(price) - intPart;
|
||||
|
||||
// Format integer part with space as thousands separator
|
||||
const intFormatted = intPart.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
|
||||
|
||||
// Build final string
|
||||
let result = price < 0 ? '-' : '';
|
||||
result += intFormatted;
|
||||
|
||||
// Add decimals only if present
|
||||
if (hasDecimals) {
|
||||
const decStr = decPart.toFixed(2).substring(2); // Get just the decimal digits
|
||||
result += ',' + decStr;
|
||||
}
|
||||
|
||||
return `${result} ${currency}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format currency amount (alias for formatPrice for backward compatibility)
|
||||
*/
|
||||
export function formatCurrency(amount: number, currency: string = 'PYG'): string {
|
||||
return formatPrice(amount, currency);
|
||||
}
|
||||
Reference in New Issue
Block a user