@@ -43,17 +43,17 @@ const getDescendantsTerm = async ( {authtoken,taxonomyUid, termUid, region, stac
4343 for ( const term of terms ) {
4444 // Push current term
4545 allTerms . push ( {
46- uid : term . uid ,
47- name : term . name ,
48- parent_uid : term . parent_uid ,
46+ uid : term ? .uid ,
47+ name : term ? .name ,
48+ parent_uid : term ? .parent_uid ,
4949 } ) ;
5050
5151 // Recursively fetch deeper descendants
52- if ( term . children_count > 0 ) {
52+ if ( term ? .children_count > 0 ) {
5353 const nestedTerms = await getDescendantsTerm ( {
5454 authtoken,
5555 taxonomyUid,
56- termUid : term . uid ,
56+ termUid : term ? .uid ,
5757 region,
5858 stackId,
5959 } ) ;
@@ -65,7 +65,7 @@ const getDescendantsTerm = async ( {authtoken,taxonomyUid, termUid, region, stac
6565 }
6666 return allTerms ;
6767 } catch ( error ) {
68- console . error ( "🚀 ~ getDescendantsTerm ~ error:" , error ) ;
68+ logger . error ( "🚀 ~ getDescendantsTerm ~ error:" , error ) ;
6969 throw error ;
7070
7171 }
@@ -92,25 +92,23 @@ const createTerms = async(
9292 for ( const term of termsData || [ ] ) {
9393 if ( term ?. uid ) {
9494 allTerms . push ( {
95- uid : term . uid ,
96- name : term . name ,
97- parent_uid : term . parent_uid ,
95+ uid : term ? .uid ,
96+ name : term ? .name ,
97+ parent_uid : term ? .parent_uid ,
9898 } ) ;
9999
100100 if ( term ?. children_count > 0 ) {
101101 const nestedTerms = await getDescendantsTerm ( {
102102 authtoken,
103103 taxonomyUid,
104- termUid : term . uid ,
104+ termUid : term ? .uid ,
105105 region,
106106 stackId,
107107 } ) ;
108108
109109 if ( Array . isArray ( nestedTerms ) ) {
110110 allTerms . push ( ...nestedTerms ) ;
111111 }
112-
113- console . info ( "🚀 ~ createTerms ~ nestedTerms:" , nestedTerms ) ;
114112 }
115113 }
116114 }
@@ -131,7 +129,7 @@ const createTerms = async(
131129 return allTerms ;
132130
133131 } catch ( error ) {
134- console . error ( "🚀 ~ createTaxonomy ~ error:" , error ) ;
132+ logger . error ( "🚀 ~ createTaxonomy ~ error:" , error ) ;
135133 throw error ;
136134
137135 }
@@ -173,31 +171,33 @@ const createTaxonomy = async ({stackId,region,userId,current_test_stack_id} :
173171 }
174172
175173 const taxonomiesDataObject : Record < string , any > = { } ;
176- res ?. data ?. taxonomies ?. forEach ( async ( taxonomy : any ) => {
177- if ( taxonomy ?. uid ) {
178- taxonomiesDataObject [ taxonomy . uid ] = {
179- uid : taxonomy ?. uid ,
180- name : taxonomy ?. name ,
181- description : taxonomy ?. description ,
182- } ;
183- const singleTaxonomy : any = { } ;
184- singleTaxonomy [ 'taxonomy' ] = {
185- uid : taxonomy ?. uid ,
186- name : taxonomy ?. name ,
187- description : taxonomy ?. description ,
174+ if ( res ?. data ?. taxonomies ) {
175+ for ( const taxonomy of res . data . taxonomies ) {
176+ if ( taxonomy ?. uid ) {
177+ taxonomiesDataObject [ taxonomy . uid ] = {
178+ uid : taxonomy ?. uid ,
179+ name : taxonomy ?. name ,
180+ description : taxonomy ?. description ,
181+ } ;
182+ const singleTaxonomy : any = { } ;
183+ singleTaxonomy [ 'taxonomy' ] = {
184+ uid : taxonomy ?. uid ,
185+ name : taxonomy ?. name ,
186+ description : taxonomy ?. description ,
187+ } ;
188+ singleTaxonomy [ 'terms' ] = await createTerms ( { authtoken, taxonomyUid : taxonomy ?. uid , region, stackId } ) ;
189+ await fs . promises . writeFile ( path . join ( taxonomiesPath , `${ taxonomy ?. uid } .json` ) , JSON . stringify ( singleTaxonomy , null , 2 ) ) ;
188190 }
189- singleTaxonomy [ 'terms' ] = await createTerms ( { authtoken, taxonomyUid : taxonomy ?. uid , region, stackId} ) ;
190- await fs . promises . writeFile ( path . join ( taxonomiesPath , `${ taxonomy ?. uid } .json` ) , JSON . stringify ( singleTaxonomy , null , 2 ) ) ;
191191 }
192- } ) ;
192+ }
193193
194194 const filePath = path . join ( taxonomiesPath , TAXONOMIES_FILE_NAME ) ;
195195 await fs . promises . writeFile ( filePath , JSON . stringify ( taxonomiesDataObject , null , 2 ) ) ;
196196
197197
198198
199199 } catch ( error ) {
200- console . error ( "🚀 ~ createTaxonomy ~ error:" , error ) ;
200+ logger . error ( "🚀 ~ createTaxonomy ~ error:" , error ) ;
201201 throw error ;
202202 }
203203
0 commit comments