feat: implement audit session module with centralized API service and axios interceptors
This commit is contained in:
2
.env
2
.env
@@ -1,2 +1,2 @@
|
|||||||
VITE_DASHBOARD_API_URL=https://sr-backend-api.takeleap.in
|
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
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { axiosClient } from './axiosClient';
|
|||||||
|
|
||||||
export const activityFeedsService = {
|
export const activityFeedsService = {
|
||||||
getAssets: async () => {
|
getAssets: async () => {
|
||||||
const response = await axiosClient.get('/api/dashboard/Master/asset_types');
|
const response = await axiosClient.get('/api/audit/Master/asset_types');
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ export const activityFeedsService = {
|
|||||||
if (params.dbName) {
|
if (params.dbName) {
|
||||||
falseParams.dbName = params.dbName;
|
falseParams.dbName = params.dbName;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response: any = await activityFeedsService.getFalseAnomaly(falseParams);
|
const response: any = await activityFeedsService.getFalseAnomaly(falseParams);
|
||||||
const resultObj = response?.result || response;
|
const resultObj = response?.result || response;
|
||||||
return {
|
return {
|
||||||
@@ -64,18 +64,18 @@ export const activityFeedsService = {
|
|||||||
|
|
||||||
// Called after normal (non-rectification) true anomaly audit
|
// Called after normal (non-rectification) true anomaly audit
|
||||||
updateAnomalyInDashboard: async (payload: { site_id: string, anomaly_id: number[] }) => {
|
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;
|
return response;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Called after rectification true anomaly audit
|
// Called after rectification true anomaly audit
|
||||||
markAnomalyCompleted: async (payload: { anomaly_id: number[], site_id: number }) => {
|
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;
|
return response;
|
||||||
},
|
},
|
||||||
|
|
||||||
getOrganizationSites: async (org_id: string) => {
|
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 }
|
params: { org_id }
|
||||||
});
|
});
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@@ -16,23 +16,13 @@ export const axiosClient = axios.create({
|
|||||||
// Request Interceptor: Attach token if available
|
// Request Interceptor: Attach token if available
|
||||||
axiosClient.interceptors.request.use(
|
axiosClient.interceptors.request.use(
|
||||||
(config) => {
|
(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;
|
const user = useAuthStore.getState().user;
|
||||||
if (user?.access_token) {
|
if (user?.access_token) {
|
||||||
config.headers['x-access-token'] = 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 };
|
config.params = { ...config.params, dbName: user.db_name };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ export const AuditSession: React.FC = () => {
|
|||||||
const [reportSending, setReportSending] = useState(false);
|
const [reportSending, setReportSending] = useState(false);
|
||||||
|
|
||||||
const DEVS = ['aromal', 'divya', 'Poonam', 'ravi', 'Kaushik', 'Saleth', 'Jagan', 'Yash', 'faraz_siddiqui', 'brinda.n', 'SasiVardhan', 'Shubham'];
|
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 () => {
|
const handleSendReport = async () => {
|
||||||
if (!reportDev || !reportMessage.trim()) return;
|
if (!reportDev || !reportMessage.trim()) return;
|
||||||
@@ -111,7 +110,7 @@ export const AuditSession: React.FC = () => {
|
|||||||
reportMessage.trim(),
|
reportMessage.trim(),
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
await axiosClient.post(ROCKETCHAT_WEBHOOK_PATH, { channel: `@${reportDev}`, text: context });
|
await axiosClient.post('/api/audit/report', { channel: `@${reportDev}`, text: context });
|
||||||
setIsReportDialogOpen(false);
|
setIsReportDialogOpen(false);
|
||||||
setReportDev('');
|
setReportDev('');
|
||||||
setReportMessage('');
|
setReportMessage('');
|
||||||
@@ -446,13 +445,13 @@ export const AuditSession: React.FC = () => {
|
|||||||
// Call API 2: Notify dashboard — only for true anomaly, endpoint differs by mode
|
// Call API 2: Notify dashboard — only for true anomaly, endpoint differs by mode
|
||||||
if (isAnomalyBool) {
|
if (isAnomalyBool) {
|
||||||
if (isRectActive) {
|
if (isRectActive) {
|
||||||
// Rectification mode: /auditor/anomaly/completed, site_id as number
|
// Rectification mode: /auditor/anomaly/close, site_id as number
|
||||||
await activityFeedsService.markAnomalyCompleted({
|
await activityFeedsService.markAnomalyCompleted({
|
||||||
anomaly_id: [currentAnomaly.id],
|
anomaly_id: [currentAnomaly.id],
|
||||||
site_id: currentAnomaly.site_id
|
site_id: currentAnomaly.site_id
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Normal audit mode: /auditor/anomaly/update, site_id as string
|
// Normal audit mode: /auditor/anomaly/submit, site_id as string
|
||||||
await activityFeedsService.updateAnomalyInDashboard({
|
await activityFeedsService.updateAnomalyInDashboard({
|
||||||
site_id: String(currentAnomaly.site_id),
|
site_id: String(currentAnomaly.site_id),
|
||||||
anomaly_id: [currentAnomaly.id]
|
anomaly_id: [currentAnomaly.id]
|
||||||
|
|||||||
Reference in New Issue
Block a user