- Database: activity_log table with indexes - Backend: Activity logger service + timeline API - Frontend: Timeline.vue with date grouping and filtering - Integration: Upload route logs activity - UI: Modern timeline with infinite scroll Backend changes: - migrations/010_activity_timeline.sql: Activity log schema - services/activity-logger.js: Log events to timeline - routes/timeline.js: GET /api/organizations/:orgId/timeline - routes/upload.js: Integrate activity logging - index.js: Register timeline route Frontend changes: - views/Timeline.vue: Timeline component with date grouping - router.js: Add /timeline route with auth - views/HomeView.vue: Add Timeline navigation button Features: - Reverse chronological event feed - Date grouping (Today, Yesterday, This Week, etc.) - Event type filtering (uploads, maintenance, etc.) - Infinite scroll pagination - User attribution - Links to source documents Resolves: Timeline feature spec
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
/**
|
|
* Activity Logger Service
|
|
* Automatically logs events to organization timeline
|
|
*/
|
|
import { getDb } from '../config/db.js';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
export async function logActivity({
|
|
organizationId,
|
|
entityId = null,
|
|
userId,
|
|
eventType,
|
|
eventAction,
|
|
eventTitle,
|
|
eventDescription = '',
|
|
metadata = {},
|
|
referenceId = null,
|
|
referenceType = null
|
|
}) {
|
|
const db = getDb();
|
|
|
|
const activity = {
|
|
id: `evt_${uuidv4()}`,
|
|
organization_id: organizationId,
|
|
entity_id: entityId,
|
|
user_id: userId,
|
|
event_type: eventType,
|
|
event_action: eventAction,
|
|
event_title: eventTitle,
|
|
event_description: eventDescription,
|
|
metadata: JSON.stringify(metadata),
|
|
reference_id: referenceId,
|
|
reference_type: referenceType,
|
|
created_at: Date.now()
|
|
};
|
|
|
|
db.prepare(`
|
|
INSERT INTO activity_log (
|
|
id, organization_id, entity_id, user_id, event_type, event_action,
|
|
event_title, event_description, metadata, reference_id, reference_type, created_at
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
`).run(
|
|
activity.id,
|
|
activity.organization_id,
|
|
activity.entity_id,
|
|
activity.user_id,
|
|
activity.event_type,
|
|
activity.event_action,
|
|
activity.event_title,
|
|
activity.event_description,
|
|
activity.metadata,
|
|
activity.reference_id,
|
|
activity.reference_type,
|
|
activity.created_at
|
|
);
|
|
|
|
console.log(`[Activity Log] ${eventType}: ${eventTitle}`);
|
|
return activity;
|
|
}
|