mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-12 01:37:40 +02:00
Merge pull request #147 from R0m1k3/1.1
Improve invoice verification caching with conflict resolution and err…
This commit is contained in:
4 files changed
+29
-3
No files matched your search
@@ -32,6 +32,7 @@ The platform is built with a clear separation of concerns, utilizing a modern fu
|
||||
- **Weather Integration:** A comprehensive, modern weather interface displays detailed weather conditions sourced directly from the Visual Crossing API with French language support. Features intelligent date comparison using the same day of the week from the previous year for more relevant weather pattern analysis (e.g., Friday August 15, 2025 vs Friday August 16, 2024).
|
||||
- **Order and Delivery Management:** Full CRUD operations for orders and deliveries, including linking orders to deliveries and managing their statuses.
|
||||
- **Reconciliation:** Functionality for reconciling Bills of Lading (BL) and invoices with immediate UI updates.
|
||||
- **Invoice Verification Cache:** Robust caching system for invoice verification results with automatic expiration and conflict resolution. Enhanced with unique constraint handling and graceful error management for production stability (August 2025).
|
||||
- **User and Permission Management:** Granular access controls ensuring that users (e.g., employees) have appropriate permissions for tasks like creating customer orders.
|
||||
- **Reporting:** Statistical reporting, including monthly summaries of deliveries based on `deliveredDate`.
|
||||
|
||||
|
||||
@@ -64,6 +64,11 @@ export class InvoiceVerificationService {
|
||||
|
||||
console.log('💾 Résultat sauvé en cache:', { invoiceReference, groupId, exists: result.exists });
|
||||
} catch (error) {
|
||||
// Gérer spécifiquement les erreurs de contrainte unique (duplicate key)
|
||||
if (error && typeof error === 'object' && 'code' in error && error.code === '23505') {
|
||||
console.log('🔄 Cache déjà existant pour cette clé, ignoré:', { invoiceReference, groupId });
|
||||
return;
|
||||
}
|
||||
console.error('❌ Erreur sauvegarde cache:', error);
|
||||
}
|
||||
}
|
||||
|
||||
+22
-2
@@ -1287,8 +1287,28 @@ export class DatabaseStorage implements IStorage {
|
||||
}
|
||||
|
||||
async createInvoiceVerificationCache(cacheData: InsertInvoiceVerificationCache): Promise<InvoiceVerificationCache> {
|
||||
const [cache] = await db.insert(invoiceVerificationCache).values(cacheData).returning();
|
||||
return cache;
|
||||
try {
|
||||
// Utiliser UPSERT pour gérer les conflits de clés
|
||||
const [cache] = await db
|
||||
.insert(invoiceVerificationCache)
|
||||
.values(cacheData)
|
||||
.onConflictDoUpdate({
|
||||
target: invoiceVerificationCache.cacheKey,
|
||||
set: {
|
||||
exists: cacheData.exists,
|
||||
matchType: cacheData.matchType,
|
||||
errorMessage: cacheData.errorMessage,
|
||||
cacheHit: cacheData.cacheHit,
|
||||
apiCallTime: cacheData.apiCallTime,
|
||||
updatedAt: new Date()
|
||||
}
|
||||
})
|
||||
.returning();
|
||||
return cache;
|
||||
} catch (error) {
|
||||
console.error('❌ Erreur création cache:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async saveInvoiceVerificationCache(cacheData: InsertInvoiceVerificationCache): Promise<InvoiceVerificationCache> {
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ export const nocodbConfig = pgTable("nocodb_config", {
|
||||
// Cache de vérification des factures
|
||||
export const invoiceVerificationCache = pgTable("invoice_verification_cache", {
|
||||
id: serial("id").primaryKey(),
|
||||
cacheKey: varchar("cache_key", { length: 255 }).notNull(),
|
||||
cacheKey: varchar("cache_key", { length: 255 }).notNull().unique(),
|
||||
groupId: integer("group_id").notNull(),
|
||||
invoiceReference: varchar("invoice_reference", { length: 255 }).notNull(),
|
||||
supplierName: varchar("supplier_name", { length: 255 }),
|
||||
|
||||
Reference in new issue
Block a user