feat: implement audit session module with centralized API service and axios interceptors

This commit is contained in:
2026-06-26 11:36:37 +05:30
parent fc61b4cdb6
commit 9d2acd126c
4 changed files with 11 additions and 22 deletions

2
.env
View File

@@ -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

View File

@@ -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;

View File

@@ -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 };
}

View File

@@ -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]