@@ -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_AUDT_DATA } from "../constants/index.js" ;
10+ import { GET_AUIDT_DATA } from "../constants/index.js" ;
1111import {
1212 HTTP_TEXTS ,
1313 HTTP_CODES ,
@@ -135,7 +135,7 @@ const createTestStack = async (req: Request): Promise<LoginServiceType> => {
135135 ) ;
136136
137137 throw new ExceptionFunction (
138- error ?. message || HTTP_TEXTS . INTERNAL_ERROR ,
138+ error ?. message || HTTP_TEXTS ? .INTERNAL_ERROR ,
139139 error ?. statusCode || error ?. status || HTTP_CODES . SERVER_ERROR
140140 ) ;
141141 }
@@ -152,22 +152,22 @@ const getAuditData = async (req: Request): Promise<any> => {
152152 const filter = req ?. params ?. filter ;
153153 const srcFunc = "getAuditData" ;
154154
155- if ( projectId . includes ( '..' ) || stackId . includes ( '..' ) || moduleName . includes ( '..' ) ) {
155+ if ( projectId ? .includes ( '..' ) || stackId ? .includes ( '..' ) || moduleName ? .includes ( '..' ) ) {
156156 throw new BadRequestError ( "Invalid projectId, stackId, or moduleName" ) ;
157157 }
158158
159159 try {
160- const mainPath = process ?. cwd ( ) ?. split ?.( GET_AUDT_DATA ?. MIGRATION ) ?. [ 0 ] ;
161- const logsDir = path . join ( mainPath , GET_AUDT_DATA ?. MIGRATION , GET_AUDT_DATA ?. API_DIR , GET_AUDT_DATA ?. MIGRATION_DATA_DIR ) ;
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 ) ;
162162
163163 const stackFolders = fs . readdirSync ( logsDir ) ;
164164
165- const stackFolder = stackFolders . find ( folder => folder . startsWith ( stackId ) ) ;
165+ const stackFolder = stackFolders ? .find ( folder => folder ? .startsWith ?. ( stackId ) ) ;
166166 if ( ! stackFolder ) {
167167 throw new BadRequestError ( "Migration data not found for this stack" ) ;
168168 }
169169
170- const auditLogPath = path . resolve ( logsDir , stackFolder , GET_AUDT_DATA ?. LOGS_DIR , GET_AUDT_DATA ?. AUDIT_DIR , GET_AUDT_DATA ?. AUDIT_REPORT ) ;
170+ const auditLogPath = path ? .resolve ( logsDir , stackFolder , GET_AUIDT_DATA ?. LOGS_DIR , GET_AUIDT_DATA ?. AUDIT_DIR , GET_AUIDT_DATA ?. AUDIT_REPORT ) ;
171171 if ( ! fs . existsSync ( auditLogPath ) ) {
172172 throw new BadRequestError ( "Audit log path not found" ) ;
173173 }
@@ -176,11 +176,11 @@ const getAuditData = async (req: Request): Promise<any> => {
176176 // Read and parse the JSON file for the module
177177 const filePath = path ?. resolve ( auditLogPath , `${ moduleName } .json` ) ;
178178 let fileData ;
179- if ( fs . existsSync ( filePath ) ) {
179+ if ( fs ? .existsSync ( filePath ) ) {
180180 const fileContent = await fsPromises . readFile ( filePath , 'utf8' ) ;
181181 try {
182182 if ( typeof fileContent === 'string' ) {
183- fileData = JSON . parse ( fileContent ) ;
183+ fileData = JSON ? .parse ( fileContent ) ;
184184 }
185185 } catch ( error ) {
186186 logger . error ( `Error parsing JSON from file ${ filePath } :` , error ) ;
@@ -192,16 +192,16 @@ 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_AUDT_DATA . FILTERALL ) {
196- const filters = filter . split ( "-" ) ;
197- moduleName === 'Entries_Select_feild' ? transformedData = transformedData . filter ( ( log ) => {
198- return filters . some ( ( filter ) => {
195+ if ( filter != GET_AUIDT_DATA ? .FILTERALL ) {
196+ const filters = filter ? .split ( "-" ) ;
197+ moduleName === 'Entries_Select_feild' ? transformedData = transformedData ? .filter ( ( log ) => {
198+ return filters ? .some ( ( filter ) => {
199199 return (
200200 log ?. display_type ?. toLowerCase ( ) ?. includes ( filter ?. toLowerCase ( ) )
201201 ) ;
202202 } ) ;
203- } ) : transformedData = transformedData . filter ( ( log ) => {
204- return filters . some ( ( filter ) => {
203+ } ) : transformedData = transformedData ? .filter ( ( log ) => {
204+ return filters ? .some ( ( filter ) => {
205205 return (
206206 log ?. data_type ?. toLowerCase ( ) ?. includes ( filter ?. toLowerCase ( ) )
207207 ) ;
@@ -211,10 +211,10 @@ const getAuditData = async (req: Request): Promise<any> => {
211211 }
212212 if ( searchText && searchText !== null && searchText !== "null" ) {
213213 transformedData = transformedData ?. filter ( ( item : any ) => {
214- return Object . values ( item ) . some ( value =>
214+ return Object ? .values ( item ) ? .some ( value =>
215215 value &&
216216 typeof value === 'string' &&
217- value ?. toLowerCase ?.( ) ?. includes ( searchText . toLowerCase ( ) )
217+ value ?. toLowerCase ?.( ) ?. includes ( searchText ? .toLowerCase ( ) )
218218 ) ;
219219 } ) ;
220220 }
@@ -248,22 +248,22 @@ const transformAndFlattenData = (data: any): Array<{ [key: string]: any, id: num
248248 const flattenedItems : Array < { [ key : string ] : any } > = [ ] ;
249249
250250 // Handle the data based on its structure
251- if ( Array . isArray ( data ) ) {
251+ if ( Array ? .isArray ( data ) ) {
252252 // If data is already an array, use it directly
253253 data . forEach ( ( item , index ) => {
254- flattenedItems . push ( {
254+ flattenedItems ? .push ( {
255255 ...item ?? { } ,
256256 uid : item ?. uid || `item-${ index } `
257257 } ) ;
258258 } ) ;
259259 } else if ( typeof data === 'object' && data !== null ) {
260- Object . entries ( data ) . forEach ( ( [ key , value ] ) => {
260+ Object ? .entries ?. ( data ) ? .forEach ( ( [ key , value ] ) => {
261261 if ( Array . isArray ( value ) ) {
262262 value . forEach ( ( item , index ) => {
263263 flattenedItems ?. push ( {
264264 ...item ?? { } ,
265265 parentKey : key ,
266- uid : item . uid || `${ key } -${ index } `
266+ uid : item ? .uid || `${ key } -${ index } `
267267 } ) ;
268268 } ) ;
269269 } else if ( typeof value === 'object' && value !== null ) {
@@ -276,7 +276,7 @@ const transformAndFlattenData = (data: any): Array<{ [key: string]: any, id: num
276276 } ) ;
277277 }
278278
279- return flattenedItems . map ( ( item , index ) => ( {
279+ return flattenedItems ? .map ( ( item , index ) => ( {
280280 ...item ?? { } ,
281281 id : index + 1
282282 } ) ) ;
0 commit comments