@@ -7,7 +7,7 @@ import https from "../utils/https.utils.js";
77import { LoginServiceType } from "../models/types.js" ;
88import getAuthtoken from "../utils/auth.utils.js" ;
99import logger from "../utils/logger.js" ;
10- import { GET_AUIDT_DATA } from "../constants/index.js" ;
10+ import { GET_AUDIT_DATA } from "../constants/index.js" ;
1111import {
1212 HTTP_TEXTS ,
1313 HTTP_CODES ,
@@ -157,8 +157,8 @@ const getAuditData = async (req: Request): Promise<any> => {
157157 }
158158
159159 try {
160- const mainPath = process ?. cwd ( ) ?. split ?.( GET_AUIDT_DATA ?. MIGRATION ) ?. [ 0 ] ;
161- const logsDir = path . join ( mainPath , GET_AUIDT_DATA ?. MIGRATION , GET_AUIDT_DATA ?. API_DIR , GET_AUIDT_DATA ?. MIGRATION_DATA_DIR ) ;
160+ const mainPath = process ?. cwd ( ) ?. split ?.( GET_AUDIT_DATA ?. MIGRATION ) ?. [ 0 ] ;
161+ const logsDir = path . join ( mainPath , GET_AUDIT_DATA ?. MIGRATION , GET_AUDIT_DATA ?. API_DIR , GET_AUDIT_DATA ?. MIGRATION_DATA_DIR ) ;
162162
163163 const stackFolders = fs . readdirSync ( logsDir ) ;
164164
@@ -167,7 +167,7 @@ const getAuditData = async (req: Request): Promise<any> => {
167167 throw new BadRequestError ( "Migration data not found for this stack" ) ;
168168 }
169169
170- const auditLogPath = path ?. resolve ( logsDir , stackFolder , GET_AUIDT_DATA ?. LOGS_DIR , GET_AUIDT_DATA ?. AUDIT_DIR , GET_AUIDT_DATA ?. AUDIT_REPORT ) ;
170+ const auditLogPath = path ?. resolve ( logsDir , stackFolder , GET_AUDIT_DATA ?. LOGS_DIR , GET_AUDIT_DATA ?. AUDIT_DIR , GET_AUDIT_DATA ?. AUDIT_REPORT ) ;
171171 if ( ! fs . existsSync ( auditLogPath ) ) {
172172 throw new BadRequestError ( "Audit log path not found" ) ;
173173 }
@@ -192,7 +192,7 @@ const getAuditData = async (req: Request): Promise<any> => {
192192 throw new BadRequestError ( `No audit data found for module: ${ moduleName } ` ) ;
193193 }
194194 let transformedData = transformAndFlattenData ( fileData ) ;
195- if ( filter != GET_AUIDT_DATA ?. FILTERALL ) {
195+ if ( filter != GET_AUDIT_DATA ?. FILTERALL ) {
196196 const filters = filter ?. split ( "-" ) ;
197197 moduleName === 'Entries_Select_feild' ? transformedData = transformedData ?. filter ( ( log ) => {
198198 return filters ?. some ( ( filter ) => {
@@ -222,7 +222,8 @@ const getAuditData = async (req: Request): Promise<any> => {
222222
223223 return {
224224 data : paginatedData ,
225- totalCount : transformedData ?. length
225+ totalCount : transformedData ?. length ,
226+ status : HTTP_CODES ?. OK
226227 } ;
227228
228229 } catch ( error : any ) {
@@ -250,24 +251,24 @@ const transformAndFlattenData = (data: any): Array<{ [key: string]: any, id: num
250251 // Handle the data based on its structure
251252 if ( Array . isArray ( data ) ) {
252253 // If data is already an array, use it directly
253- data . forEach ( ( item , index ) => {
254- flattenedItems . push ( {
254+ data ? .forEach ( ( item , index ) => {
255+ flattenedItems ? .push ( {
255256 ...item ?? { } ,
256- uid : item . uid || `item-${ index } `
257+ uid : item ? .uid || `item-${ index } `
257258 } ) ;
258259 } ) ;
259260 } else if ( typeof data === 'object' && data !== null ) {
260261 Object ?. entries ?.( data ) ?. forEach ( ( [ key , value ] ) => {
261262 if ( Array . isArray ( value ) ) {
262- value . forEach ( ( item , index ) => {
263+ value ? .forEach ( ( item , index ) => {
263264 flattenedItems ?. push ( {
264265 ...item ?? { } ,
265266 parentKey : key ,
266267 uid : item ?. uid || `${ key } -${ index } `
267268 } ) ;
268269 } ) ;
269270 } else if ( typeof value === 'object' && value !== null ) {
270- flattenedItems . push ( {
271+ flattenedItems ? .push ( {
271272 ...value ,
272273 key,
273274 uid : ( value as any ) ?. uid || key
@@ -972,9 +973,9 @@ const getLogs = async (req: Request): Promise<any> => {
972973 if ( ! logEntries ?. length ) {
973974 return { logs : [ ] , total : 0 } ;
974975 }
975- const filterOptions = Array . from ( new Set ( logEntries . map ( ( log ) => log . level ) ) ) ;
976- const auditStartIndex = logEntries . findIndex ( log => log . message . includes ( "Starting audit process" ) ) ;
977- const auditEndIndex = logEntries . findIndex ( log => log . message . includes ( "Audit process completed" ) ) ;
976+ const filterOptions = Array ? .from ( new Set ( logEntries ? .map ( ( log ) => log ? .level ) ) ) ;
977+ const auditStartIndex = logEntries ? .findIndex ?. ( log => log ? .message ? .includes ( "Starting audit process" ) ) ;
978+ const auditEndIndex = logEntries ? .findIndex ?. ( log => log ? .message ? .includes ( "Audit process completed" ) ) ;
978979 logEntries = [
979980 ...logEntries . slice ( 0 , auditStartIndex ) ,
980981 ...logEntries . slice ( auditEndIndex + 1 )
@@ -1000,6 +1001,7 @@ const getLogs = async (req: Request): Promise<any> => {
10001001 logs : paginatedLogs ,
10011002 total : logEntries ?. length ?? 0 ,
10021003 filterOptions : filterOptions ,
1004+ status : HTTP_CODES ?. OK
10031005 } ;
10041006 } else {
10051007 logger . error ( getLogMessage ( srcFunc , HTTP_TEXTS . LOGS_NOT_FOUND ) ) ;
0 commit comments