File tree Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -658,3 +658,46 @@ export async function getTerms({
658658 result : response . result ,
659659 } ;
660660}
661+
662+ export async function getChildrenOfTerms ( {
663+ taxonomyName,
664+ language,
665+ pageNumber,
666+ pageSize,
667+ sort,
668+ filter,
669+ projection,
670+ excludeCulture,
671+ cluster,
672+ } ) {
673+ const response = await server . loadJson (
674+ `${ Config . apiUrl } ${ Endpoints . PROJECT . DATABASE . TAXONOMY . TERM . GET_CHILDREN (
675+ taxonomyName
676+ ) } `,
677+ {
678+ method : 'POST' ,
679+ headers : {
680+ 'X-CM-ProjectId' : Config . projectId ,
681+ 'X-CM-Cluster' : cluster ,
682+ Authorization : `Bearer ${ Config . secretKey } ` ,
683+ Accept : 'application/json' ,
684+ 'Content-Type' : 'application/json' ,
685+ 'Accept-Language' : language || 'en' ,
686+ } ,
687+ body : JSON . stringify ( {
688+ pageSize : pageSize || Config . tablePageSize ,
689+ pageNumber : pageNumber || 0 ,
690+ projection : objectOrStringToString ( projection ) ,
691+ filter : objectOrStringToString ( filter ) ,
692+ sort : objectOrStringToString ( sort ) ,
693+ excludeCulture,
694+ } ) ,
695+ }
696+ ) ;
697+
698+ if ( ! response ) return null ;
699+ return {
700+ totalCount : response . totalCount ,
701+ result : response . result ,
702+ } ;
703+ }
Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ export const CONFIG = {
4141 TERM : {
4242 GET : ( id ) => `/v2/db/terms/${ id } ` ,
4343 GET_ALL : ( taxonomyName ) => `/v2/db/taxonomies/${ taxonomyName } /terms` ,
44+ GET_CHILDREN : ( taxonomyName ) =>
45+ `/db/taxonomies/${ taxonomyName } /terms/children` ,
4446 } ,
4547 SYSTEM : {
4648 GET_TERMS : ( taxonomyName ) => `/v2/taxonomies/${ taxonomyName } /terms` ,
Original file line number Diff line number Diff line change 1- import { getRecords } from 'Components/db' ;
1+ import { getRecords , getChildrenOfTerms } from 'Components/db' ;
22import config from 'Config' ;
33
44require ( 'dotenv' ) . config ( ) ;
@@ -19,4 +19,10 @@ describe('db tests', () => {
1919 const response = await getRecords ( request ) ;
2020 expect ( response . totalCount ) . toBe ( 2 ) ;
2121 } ) ;
22+
23+ test ( 'get all children of specified taxonomy' , async ( ) => {
24+ const request = { taxonomyName : 'countries' } ;
25+ const response = await getChildrenOfTerms ( request ) ;
26+ expect ( response . totalCount ) . toBe ( 3 ) ;
27+ } ) ;
2228} ) ;
You can’t perform that action at this time.
0 commit comments