Files
Zumri-Backend/app/services/activity.service.js
T
Sathira Sri Sathara b6b345f245 feat: Implement Phase 2 cross-cutting services with email and notification enhancements
- Refactor email verification and password reset utilities to use new email service.
- Introduce email delivery queue and notification delivery model for better tracking.
- Enhance file validation and storage services for improved security and ownership management.
- Add cron job for cleaning inactive notifications with retention policy.
- Update document worker to handle document generation and storage more efficiently.
- Implement logging improvements in activity and log workers.
- Create comprehensive documentation for new API endpoints and services.
- Add unit tests for file validation and notification policies to ensure robustness.
2026-09-03 14:22:34 +05:30

48 lines
1.4 KiB
JavaScript

/**
* Copyright (c) 2026 Niolla
* All rights reserved.
*
* This source code is proprietary and confidential.
* Unauthorized copying, modification, distribution, or use
* of this file, via any medium, is strictly prohibited.
*/
// app/services/activity.service.js
const activityQueue = require("../queues/activity.queue");
const logActivity = async ({
user,
description,
type = "ACTION",
module,
eventId,
targetType,
targetId,
requestId,
ipAddress,
userAgent,
metadata,
}) => {
try {
const safeMetadata = metadata && JSON.parse(JSON.stringify(metadata, (key, value) => /password|otp|token|authorization|cookie/i.test(key) ? "[REDACTED]" : value));
const id = eventId || require("crypto").randomUUID();
await activityQueue.add("log-activity", {
event_id: id,
user_id: user?.id || user?.user_id || null,
username: user?.firstName || "System",
activity_description: description,
module: module,
activity_type: type,
activity_time: new Date(),
activity_date: new Date().toISOString().split("T")[0],
target_type: targetType, target_id: targetId, request_id: requestId,
ip_address: ipAddress, user_agent: userAgent, metadata: safeMetadata, occurred_at: new Date(),
}, { jobId: `activity-${id}` });
} catch (err) {
console.error("Queue push error:", err.message);
}
};
module.exports = { logActivity };