33 create ,
44 update ,
55 deleteEntity ,
6- fetch
6+ fetch ,
7+ fetchAll
78} from '../../../entity'
89import error from '../../../core/contentstackError'
910import ContentstackCollection from '../../../contentstackCollection'
@@ -69,9 +70,8 @@ export function PublishRules (http, data = {}) {
6970 *
7071 */
7172 this . fetch = fetch ( http , 'publishing_rule' )
72-
7373 } else {
74- /**
74+ /**
7575 * @description The Create Publish Rules request allows you to create publish rules for the publish rules of a stack.
7676 * @memberof PublishRules
7777 * @func create
@@ -96,10 +96,10 @@ export function PublishRules (http, data = {}) {
9696 * client.stack().publishRules().create({ publishing_rule })
9797 * .then((publishRules) => console.log(publishRules))
9898 */
99- this . create = create ( { http : http } )
99+ this . create = create ( { http : http } )
100100
101- /**
102- * @description The Get all Publish Rules request retrieves the details of all the Publish rules of a workflow.
101+ /**
102+ * @description The Get all Publish Rules request retrieves the details of all the Publish rules of a workflow.
103103 * @memberof Publish Rules
104104 * @func fetchAll
105105 * @param {String } content_types Enter a comma-separated list of content type UIDs for filtering publish rules on its basis.
@@ -115,34 +115,14 @@ export function PublishRules (http, data = {}) {
115115 * .then((collection) => console.log(collection))
116116 *
117117 */
118- this . fetchAll = async ( params ) => {
119- const headers = { }
120- if ( this . stackHeaders ) {
121- headers . headers = this . stackHeaders
122- }
123- if ( params ) {
124- headers . params = {
125- ...cloneDeep ( params )
126- }
127- }
128- try {
129- const response = await http . get ( this . urlPath , headers )
130- if ( response . data ) {
131- return new ContentstackCollection ( response , http , null , PublishRulesCollection )
132- } else {
133- throw error ( response )
134- }
135- } catch ( err ) {
136- throw error ( err )
137- }
138- }
139- }
118+ this . fetchAll = fetchAll ( http , PublishRulesCollection )
119+ }
140120}
141121
142122export function PublishRulesCollection ( http , data ) {
143- const obj = cloneDeep ( data . publishing_rules ) || [ ]
144- const publishRulesollection = obj . map ( ( userdata ) => {
145- return new PublishRules ( http , { publishing_rule : userdata , stackHeaders : data . stackHeaders } )
146- } )
147- return publishRulesollection
123+ const obj = cloneDeep ( data . publishing_rules ) || [ ]
124+ const publishRulesollection = obj . map ( ( userdata ) => {
125+ return new PublishRules ( http , { publishing_rule : userdata , stackHeaders : data . stackHeaders } )
126+ } )
127+ return publishRulesollection
148128}
0 commit comments