Calendar/src/repositories/MockAuditRepository.ts

50 lines
1.6 KiB
TypeScript
Raw Normal View History

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';
async sendCreate(entity: IAuditEntry): Promise<IAuditEntry> {
// 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()
});
return entity;
}
async sendUpdate(_id: string, entity: IAuditEntry): Promise<IAuditEntry> {
// 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;
}
}