Audit Log Collection Design Problem
✓ Published0🌍 Public
RRestuta
Last edited Jan 25, 2019
Created on Jan 16, 2019
This example presents a design problem for collecting audit logs alongside object updates while keeping business logic agnostic. The code defines a `foo` function that calls `applyUpdatesWithAudit` multiple times, while `updateWithAuditLog` returns both the updated object and an audit record. Abstracting the audit collection into a `createFoo` wrapper ensures that `foo` performs only updates, while delegated functions like `saveAuditRecordsToDb` and `saveUpdatesToDb` handle database writes. The solution runs entirely in JavaScript with async/await, demonstrating a pattern for batching in-memory updates and audit records for a two-call persistence flow.
AI-generated description