import { axiosClient } from './axiosClient'; export const activityFeedsService = { getAssets: async () => { const response = await axiosClient.get('/api/audit/Master/asset_types'); return response; }, getHistoryDates: async (isRectificationEnabled: boolean, siteIds?: string, auditedByMe = false) => { const response = await axiosClient.get('/api/audit/anomaly/get_history_dates', { params: { isRectificationEnabled, siteIds: siteIds || '', auditedByMe } }); return response; }, getHistory: async (params: any) => { if (params.isRectificationEnabled) { const cleanParams = { ...params }; delete cleanParams.auditStatus; const response = await axiosClient.get('/api/audit/anomaly/history', { params: cleanParams }); return response; } if (params.auditStatus === 'False Audits' || params.isTrueFalse === 'true') { const pageIndex = params.pageSize ? Math.floor(params.pageNo / params.pageSize) + 1 : 1; const falseParams: any = { fromDate: params.fromDate || '', toDate: params.tillDate || '', asset_id: params.assetsIds || '', page: pageIndex, limit: params.pageSize || 20, site_id: params.siteIds || '' }; if (params.dbName) { falseParams.dbName = params.dbName; } const response: any = await activityFeedsService.getFalseAnomaly(falseParams); const resultObj = response?.result || response; return { anomalies: resultObj?.data || [], count: resultObj?.totalCount || 0 }; } const cleanParams = { ...params }; delete cleanParams.auditStatus; const response = await axiosClient.get('/api/audit/anomaly/history', { params: cleanParams }); return response; }, // Mocking update anomaly updateAuditedAnomaly: async (site_id: string, anomaly_id: string, payload: any) => { const response = await axiosClient.put(`/api/audit/anomalies/updateAuditedAnomaly/${site_id}/${anomaly_id}`, payload); return response; }, updateAnomaly: async (anomalies: any[], isRectificationEnabled: boolean) => { const response = await axiosClient.post('/api/audit/anomaly', anomalies, { params: { isRectificationEnabled } }); return response; }, // Corrects a single record's asset classification. The backend resolves // the canonical asset_name from the central catalog and returns it. updateAnomalyAsset: async (id: number, assetId: number, isRectificationEnabled: boolean) => { const response = await axiosClient.put('/api/audit/anomaly/asset', { id, asset_id: assetId }, { params: { isRectificationEnabled } } ); return response as unknown as { id: number; asset_id: number; asset_name: string }; }, // 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/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/close', payload); return response; }, // Called after a rectification FALSE + 'true others' audit - the defect is // NOT fixed, so this re-opens/creates it in the work-order layer with // asset status DAMAGED. Backend only accepts rows already saved with // Audit_value = 'true others' (exact lowercase). rectifiedFalse: async (payload: { site_id: number; anomaly_id: number[] }) => { const response = await axiosClient.post('/api/audit/auditor/rectified/false', payload); return response; }, // Manual test-frame capture: extract the frame at `timestamp` (seconds) from // the record's video, store it as a new image, and repoint Frame_Test at it. // Returns { frame_test } - the new relative path to display/use. captureFrame: async (payload: { site_id: number | string; anomaly_id: number; table: 'audits' | 'rectification'; timestamp: number }) => { const response = await axiosClient.post('/api/audit/auditor/anomaly/capture-frame', payload); return response; }, getOrganizationSites: async (org_id: string) => { const response = await axiosClient.get('/api/audit/Master/site', { params: { org_id } }); return response; }, // Dashboard stats scoped to the logged-in user (org-wide for // ADMIN/MODERATOR): overall workload, today's activity, and the workload // split into batches of 50 in the same order the audit session walks. // sortBy/sortDir keep the batch numbering aligned with the feed/session // order when a custom sort is active (backend mirrors the same whitelist). getUserStats: async (isRectificationEnabled: boolean, sortBy?: string, sortDir?: string) => { const response = await axiosClient.get('/api/audit/anomaly/user-stats', { params: { isRectificationEnabled, sortBy: sortBy || '', sortDir: sortDir || '' } }); return response as unknown as { scoped: boolean; batchSize: number; overall: { total: number; audited: number; pending: number; anomaliesFound: number }; today: { audited: number; anomaliesFound: number }; batches: { batch: number; total: number; audited: number; pending: number; anomaliesFound: number }[]; }; }, getFalseAnomaly: async (params: any) => { const response = await axiosClient.get('/api/audit/asset/get-false-Anomaly', { params }); return response; }, bulkDelete: async (payload: any) => { const response = await axiosClient.post('/api/audit/bulk/delete', payload); return response; } };