From 9d2acd126c3142ab19b86ef87eadb95d0da4f6f5 Mon Sep 17 00:00:00 2001 From: kaushik Date: Fri, 26 Jun 2026 11:36:37 +0530 Subject: [PATCH] feat: implement audit session module with centralized API service and axios interceptors --- .env | 2 +- src/api/activityFeedsService.ts | 10 +++++----- src/api/axiosClient.ts | 14 ++------------ src/pages/audit-session/AuditSession.tsx | 7 +++---- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/.env b/.env index cd20510..353c7e2 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ VITE_DASHBOARD_API_URL=https://sr-backend-api.takeleap.in -VITE_AUDIT_API_URL=https://sr-audit.takeleap.in +VITE_AUDIT_API_URL=http://localhost:7514 diff --git a/src/api/activityFeedsService.ts b/src/api/activityFeedsService.ts index a97dd47..5fe0b94 100644 --- a/src/api/activityFeedsService.ts +++ b/src/api/activityFeedsService.ts @@ -2,7 +2,7 @@ import { axiosClient } from './axiosClient'; export const activityFeedsService = { getAssets: async () => { - const response = await axiosClient.get('/api/dashboard/Master/asset_types'); + const response = await axiosClient.get('/api/audit/Master/asset_types'); return response; }, @@ -34,7 +34,7 @@ export const activityFeedsService = { if (params.dbName) { falseParams.dbName = params.dbName; } - + const response: any = await activityFeedsService.getFalseAnomaly(falseParams); const resultObj = response?.result || response; return { @@ -64,18 +64,18 @@ export const activityFeedsService = { // Called after normal (non-rectification) true anomaly audit updateAnomalyInDashboard: async (payload: { site_id: string, anomaly_id: number[] }) => { - const response = await axiosClient.post('/api/audit/auditor/anomaly/update', payload); + const response = await axiosClient.post('/api/audit/auditor/anomaly/submit', payload); return response; }, // Called after rectification true anomaly audit markAnomalyCompleted: async (payload: { anomaly_id: number[], site_id: number }) => { - const response = await axiosClient.post('/api/audit/auditor/anomaly/completed', payload); + const response = await axiosClient.post('/api/audit/auditor/anomaly/close', payload); return response; }, getOrganizationSites: async (org_id: string) => { - const response = await axiosClient.get('/api/dashboard/Master/site', { + const response = await axiosClient.get('/api/audit/Master/site', { params: { org_id } }); return response; diff --git a/src/api/axiosClient.ts b/src/api/axiosClient.ts index 30c6435..890c0e0 100644 --- a/src/api/axiosClient.ts +++ b/src/api/axiosClient.ts @@ -16,23 +16,13 @@ export const axiosClient = axios.create({ // Request Interceptor: Attach token if available axiosClient.interceptors.request.use( (config) => { - // Rocket.Chat webhook: skip auth headers, skip dbName, let Vite proxy handle in dev - if (config.url?.startsWith('/api/rocketchat')) { - if (import.meta.env.DEV) { - // Leave URL as-is — Vite proxy rewrites /api/rocketchat → https://text.seekright.com - return config; - } - // Production: rewrite URL directly (no Vite proxy) - const rcUrl = import.meta.env.VITE_ROCKETCHAT_URL || 'https://text.seekright.com'; - config.url = config.url.replace('/api/rocketchat', rcUrl); - return config; - } + const user = useAuthStore.getState().user; if (user?.access_token) { config.headers['x-access-token'] = user.access_token; } - if (user?.db_name) { + if (user?.db_name && !config.url?.includes('asset_types')) { config.params = { ...config.params, dbName: user.db_name }; } diff --git a/src/pages/audit-session/AuditSession.tsx b/src/pages/audit-session/AuditSession.tsx index 6f65cf0..c8d5049 100644 --- a/src/pages/audit-session/AuditSession.tsx +++ b/src/pages/audit-session/AuditSession.tsx @@ -67,7 +67,6 @@ export const AuditSession: React.FC = () => { const [reportSending, setReportSending] = useState(false); const DEVS = ['aromal', 'divya', 'Poonam', 'ravi', 'Kaushik', 'Saleth', 'Jagan', 'Yash', 'faraz_siddiqui', 'brinda.n', 'SasiVardhan', 'Shubham']; - const ROCKETCHAT_WEBHOOK_PATH = '/api/rocketchat/hooks/6a22ad73a88367bc6e1095a2/xcHkbDSce5rCwofdBZF3ri2rb6ntxT2mahqT6Gg7iKdectYk'; const handleSendReport = async () => { if (!reportDev || !reportMessage.trim()) return; @@ -111,7 +110,7 @@ export const AuditSession: React.FC = () => { reportMessage.trim(), ].join('\n'); - await axiosClient.post(ROCKETCHAT_WEBHOOK_PATH, { channel: `@${reportDev}`, text: context }); + await axiosClient.post('/api/audit/report', { channel: `@${reportDev}`, text: context }); setIsReportDialogOpen(false); setReportDev(''); setReportMessage(''); @@ -446,13 +445,13 @@ export const AuditSession: React.FC = () => { // Call API 2: Notify dashboard — only for true anomaly, endpoint differs by mode if (isAnomalyBool) { if (isRectActive) { - // Rectification mode: /auditor/anomaly/completed, site_id as number + // Rectification mode: /auditor/anomaly/close, site_id as number await activityFeedsService.markAnomalyCompleted({ anomaly_id: [currentAnomaly.id], site_id: currentAnomaly.site_id }); } else { - // Normal audit mode: /auditor/anomaly/update, site_id as string + // Normal audit mode: /auditor/anomaly/submit, site_id as string await activityFeedsService.updateAnomalyInDashboard({ site_id: String(currentAnomaly.site_id), anomaly_id: [currentAnomaly.id]