2025-11-21 23:23:04 +01:00
|
|
|
import { IApiRepository } from './IApiRepository';
|
|
|
|
|
import { IAuditEntry } from '../types/AuditTypes';
|
|
|
|
|
import { EntityType } from '../types/CalendarTypes';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* MockAuditRepository - Mock API repository for audit entries
|
|
|
|
|
*
|
|
|
|
|
* In production, this would send audit entries to the backend.
|
|
|
|
|
* For development/testing, it just logs the operations.
|
|
|
|
|
*/
|
|
|
|
|
export class MockAuditRepository implements IApiRepository<IAuditEntry> {
|
|
|
|
|
readonly entityType: EntityType = 'Audit';
|
|
|
|
|
|
2025-11-22 19:42:12 +01:00
|
|
|
async sendCreate(entity: IAuditEntry): Promise<IAuditEntry> {
|
2025-11-21 23:23:04 +01:00
|
|
|
// Simulate API call delay
|
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
|
|
|
|
|
|
|
console.log('MockAuditRepository: Audit entry synced to backend:', {
|
|
|
|
|
id: entity.id,
|
|
|
|
|
entityType: entity.entityType,
|
|
|
|
|
entityId: entity.entityId,
|
|
|
|
|
operation: entity.operation,
|
|
|
|
|
timestamp: new Date(entity.timestamp).toISOString()
|
|
|
|
|
});
|
2025-11-22 19:42:12 +01:00
|
|
|
|
|
|
|
|
return entity;
|
2025-11-21 23:23:04 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-17 23:54:25 +01:00
|
|
|
async sendUpdate(_id: string, _entity: IAuditEntry): Promise<IAuditEntry> {
|
2025-11-21 23:23:04 +01:00
|
|
|
// Audit entries are immutable - updates should not happen
|
|
|
|
|
throw new Error('Audit entries cannot be updated');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async sendDelete(_id: string): Promise<void> {
|
|
|
|
|
// Audit entries should never be deleted
|
|
|
|
|
throw new Error('Audit entries cannot be deleted');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fetchAll(): Promise<IAuditEntry[]> {
|
|
|
|
|
// For now, return empty array - audit entries are local-first
|
|
|
|
|
// In production, this could fetch audit history from backend
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fetchById(_id: string): Promise<IAuditEntry | null> {
|
|
|
|
|
// For now, return null - audit entries are local-first
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|