@@ -3,13 +3,9 @@ import {
3
3
create ,
4
4
update ,
5
5
deleteEntity ,
6
- fetch ,
7
- upload ,
8
- parseData
6
+ fetch
9
7
} from '../../entity'
10
8
import error from '../../core/contentstackError'
11
- import FormData from 'form-data'
12
- import { createReadStream } from 'fs'
13
9
import ContentstackCollection from '../../contentstackCollection'
14
10
import { PublishRules , PublishRulesCollection } from './publishRules'
15
11
@@ -60,20 +56,20 @@ export function Workflow (http, data = {}) {
60
56
*
61
57
*/
62
58
this . disable = async function ( ) {
63
- try {
64
- const response = await http . get ( `/workflows/${ this . uid } /disable` , {
65
- headers : {
66
- ...cloneDeep ( this . stackHeaders )
67
- } ,
68
- } )
69
- if ( response . data ) {
70
- return response . data
71
- } else {
72
- throw error ( response )
73
- }
74
- } catch ( err ) {
75
- throw error ( err )
59
+ try {
60
+ const response = await http . get ( `/workflows/${ this . uid } /disable` , {
61
+ headers : {
62
+ ...cloneDeep ( this . stackHeaders )
63
+ }
64
+ } )
65
+ if ( response . data ) {
66
+ return response . data
67
+ } else {
68
+ throw error ( response )
76
69
}
70
+ } catch ( err ) {
71
+ throw error ( err )
72
+ }
77
73
}
78
74
79
75
/**
@@ -90,23 +86,22 @@ export function Workflow (http, data = {}) {
90
86
*
91
87
*/
92
88
this . enable = async function ( ) {
93
- try {
94
- const response = await http . get ( `/workflows/${ this . uid } /enable` , {
95
- headers : {
96
- ...cloneDeep ( this . stackHeaders )
97
- } ,
98
- } )
99
- if ( response . data ) {
100
- return response . data
101
- } else {
102
- throw error ( response )
103
- }
104
- } catch ( err ) {
105
- throw error ( err )
89
+ try {
90
+ const response = await http . get ( `/workflows/${ this . uid } /enable` , {
91
+ headers : {
92
+ ...cloneDeep ( this . stackHeaders )
93
+ }
94
+ } )
95
+ if ( response . data ) {
96
+ return response . data
97
+ } else {
98
+ throw error ( response )
106
99
}
100
+ } catch ( err ) {
101
+ throw error ( err )
102
+ }
107
103
}
108
104
109
-
110
105
/**
111
106
* @description The Delete Workflow call is used to delete an existing Workflow permanently from your Stack.
112
107
* @memberof Workflow
@@ -135,11 +130,10 @@ export function Workflow (http, data = {}) {
135
130
*
136
131
*/
137
132
this . fetch = fetch ( http , 'workflow' )
138
-
139
133
} else {
140
134
this . contentType = ( contentTypeUID ) => {
141
- if ( contentTypeUID ) {
142
- /**
135
+ if ( contentTypeUID ) {
136
+ /**
143
137
* @description The Delete Workflow call is used to delete an existing Workflow permanently from your Stack.
144
138
* @memberof Workflow
145
139
* @func getPublishRules
@@ -155,34 +149,34 @@ export function Workflow (http, data = {}) {
155
149
* client.stack({ api_key: 'api_key'}).workflow('workflow_uid').contentType('contentType_uid').getPublishRules()
156
150
* .then((collection) => console.log(collection))
157
151
*/
158
- async function getPublishRules ( params ) {
159
- const headers = { }
160
- if ( this . stackHeaders ) {
161
- headers . headers = this . stackHeaders
162
- }
163
- if ( params ) {
164
- headers . params = {
165
- ...cloneDeep ( params )
166
- }
167
- }
168
- try {
169
- const response = await http . get ( `/workflows/content_type/${ contentTypeUID } ` , headers )
170
- if ( response . data ) {
171
- return new ContentstackCollection ( response , http , this . stackHeaders , PublishRulesCollection )
172
- } else {
173
- throw error ( response )
174
- }
175
- } catch ( err ) {
176
- throw error ( err )
177
- }
152
+ async function getPublishRules ( params ) {
153
+ const headers = { }
154
+ if ( this . stackHeaders ) {
155
+ headers . headers = this . stackHeaders
156
+ }
157
+ if ( params ) {
158
+ headers . params = {
159
+ ...cloneDeep ( params )
178
160
}
179
- return {
180
- getPublishRules,
181
- stackHeaders : { ...this . stackHeaders }
161
+ }
162
+ try {
163
+ const response = await http . get ( `/workflows/content_type/${ contentTypeUID } ` , headers )
164
+ if ( response . data ) {
165
+ return new ContentstackCollection ( response , http , this . stackHeaders , PublishRulesCollection )
166
+ } else {
167
+ throw error ( response )
182
168
}
169
+ } catch ( err ) {
170
+ throw error ( err )
171
+ }
183
172
}
173
+ return {
174
+ getPublishRules,
175
+ stackHeaders : { ...this . stackHeaders }
176
+ }
177
+ }
184
178
}
185
- /**
179
+ /**
186
180
* @description The Create a Workflow request allows you to create a Workflow.
187
181
* @memberof Workflow
188
182
* @func create
@@ -191,7 +185,7 @@ export function Workflow (http, data = {}) {
191
185
* @example
192
186
* import * as contentstack from '@contentstack/management'
193
187
* const client = contentstack.client()
194
- *
188
+ *
195
189
* const workflow = {
196
190
* "workflow_stages": [
197
191
* {
@@ -251,11 +245,11 @@ export function Workflow (http, data = {}) {
251
245
* ]
252
246
* }
253
247
* client.stack().workflow().create({ workflow })
254
- * .then((workflow) => console.log(workflow))
248
+ * .then((workflow) => console.log(workflow))
255
249
*/
256
- this . create = create ( { http : http } )
250
+ this . create = create ( { http : http } )
257
251
258
- /**
252
+ /**
259
253
* @description The Get all Workflows request retrieves the details of all the Workflows of a stack.
260
254
* @memberof Workflow
261
255
* @func fetchAll
@@ -271,29 +265,29 @@ export function Workflow (http, data = {}) {
271
265
* .then((collection) => console.log(collection))
272
266
*
273
267
*/
274
- this . fetchAll = async ( params ) => {
275
- const headers = { }
276
- if ( this . stackHeaders ) {
277
- headers . headers = this . stackHeaders
278
- }
279
- if ( params ) {
280
- headers . params = {
281
- ...cloneDeep ( params )
282
- }
283
- }
284
- try {
285
- const response = await http . get ( this . urlPath , headers )
286
- if ( response . data ) {
287
- return new ContentstackCollection ( response , http , null , WorkflowCollection )
288
- } else {
289
- throw error ( response )
290
- }
291
- } catch ( err ) {
292
- throw error ( err )
293
- }
268
+ this . fetchAll = async ( params ) => {
269
+ const headers = { }
270
+ if ( this . stackHeaders ) {
271
+ headers . headers = this . stackHeaders
272
+ }
273
+ if ( params ) {
274
+ headers . params = {
275
+ ...cloneDeep ( params )
276
+ }
277
+ }
278
+ try {
279
+ const response = await http . get ( this . urlPath , headers )
280
+ if ( response . data ) {
281
+ return new ContentstackCollection ( response , http , null , WorkflowCollection )
282
+ } else {
283
+ throw error ( response )
294
284
}
285
+ } catch ( err ) {
286
+ throw error ( err )
287
+ }
288
+ }
295
289
296
- /**
290
+ /**
297
291
* @description The Publish rule allow you to create, fetch, delete, update the publish rules.
298
292
* @memberof Workflow
299
293
* @func publishRule
@@ -305,25 +299,25 @@ export function Workflow (http, data = {}) {
305
299
*
306
300
* client.stack({ api_key: 'api_key'}).workflow().publishRule().fetchAll()
307
301
* .then((collection) => console.log(collection))
308
- *
302
+ *
309
303
* client.stack({ api_key: 'api_key'}).workflow().publishRule('rule_uid').fetch()
310
304
* .then((publishrule) => console.log(publishrule))
311
305
*
312
306
*/
313
- this . publishRule = ( ruleUid = null ) => {
314
- const publishInfo = { stackHeaders : this . stackHeaders }
315
- if ( ruleUid ) {
316
- publishInfo . publishing_rule = { uid : ruleUid }
317
- }
318
- return new PublishRules ( http , publishInfo )
319
- }
307
+ this . publishRule = ( ruleUid = null ) => {
308
+ const publishInfo = { stackHeaders : this . stackHeaders }
309
+ if ( ruleUid ) {
310
+ publishInfo . publishing_rule = { uid : ruleUid }
311
+ }
312
+ return new PublishRules ( http , publishInfo )
320
313
}
314
+ }
321
315
}
322
316
323
317
export function WorkflowCollection ( http , data ) {
324
- const obj = cloneDeep ( data . workflows ) || [ ]
325
- const workflowCollection = obj . map ( ( userdata ) => {
326
- return new Workflow ( http , { workflow : userdata , stackHeaders : data . stackHeaders } )
327
- } )
328
- return workflowCollection
329
- }
318
+ const obj = cloneDeep ( data . workflows ) || [ ]
319
+ const workflowCollection = obj . map ( ( userdata ) => {
320
+ return new Workflow ( http , { workflow : userdata , stackHeaders : data . stackHeaders } )
321
+ } )
322
+ return workflowCollection
323
+ }
0 commit comments