@@ -3,13 +3,9 @@ import {
33 create ,
44 update ,
55 deleteEntity ,
6- fetch ,
7- upload ,
8- parseData
6+ fetch
97} from '../../entity'
108import error from '../../core/contentstackError'
11- import FormData from 'form-data'
12- import { createReadStream } from 'fs'
139import ContentstackCollection from '../../contentstackCollection'
1410import { PublishRules , PublishRulesCollection } from './publishRules'
1511
@@ -60,20 +56,20 @@ export function Workflow (http, data = {}) {
6056 *
6157 */
6258 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 )
7669 }
70+ } catch ( err ) {
71+ throw error ( err )
72+ }
7773 }
7874
7975 /**
@@ -90,23 +86,22 @@ export function Workflow (http, data = {}) {
9086 *
9187 */
9288 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 )
10699 }
100+ } catch ( err ) {
101+ throw error ( err )
102+ }
107103 }
108104
109-
110105 /**
111106 * @description The Delete Workflow call is used to delete an existing Workflow permanently from your Stack.
112107 * @memberof Workflow
@@ -135,11 +130,10 @@ export function Workflow (http, data = {}) {
135130 *
136131 */
137132 this . fetch = fetch ( http , 'workflow' )
138-
139133 } else {
140134 this . contentType = ( contentTypeUID ) => {
141- if ( contentTypeUID ) {
142- /**
135+ if ( contentTypeUID ) {
136+ /**
143137 * @description The Delete Workflow call is used to delete an existing Workflow permanently from your Stack.
144138 * @memberof Workflow
145139 * @func getPublishRules
@@ -155,34 +149,34 @@ export function Workflow (http, data = {}) {
155149 * client.stack({ api_key: 'api_key'}).workflow('workflow_uid').contentType('contentType_uid').getPublishRules()
156150 * .then((collection) => console.log(collection))
157151 */
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 )
178160 }
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 )
182168 }
169+ } catch ( err ) {
170+ throw error ( err )
171+ }
183172 }
173+ return {
174+ getPublishRules,
175+ stackHeaders : { ...this . stackHeaders }
176+ }
177+ }
184178 }
185- /**
179+ /**
186180 * @description The Create a Workflow request allows you to create a Workflow.
187181 * @memberof Workflow
188182 * @func create
@@ -191,7 +185,7 @@ export function Workflow (http, data = {}) {
191185 * @example
192186 * import * as contentstack from '@contentstack/management'
193187 * const client = contentstack.client()
194- *
188+ *
195189 * const workflow = {
196190 * "workflow_stages": [
197191 * {
@@ -251,11 +245,11 @@ export function Workflow (http, data = {}) {
251245 * ]
252246 * }
253247 * client.stack().workflow().create({ workflow })
254- * .then((workflow) => console.log(workflow))
248+ * .then((workflow) => console.log(workflow))
255249 */
256- this . create = create ( { http : http } )
250+ this . create = create ( { http : http } )
257251
258- /**
252+ /**
259253 * @description The Get all Workflows request retrieves the details of all the Workflows of a stack.
260254 * @memberof Workflow
261255 * @func fetchAll
@@ -271,29 +265,29 @@ export function Workflow (http, data = {}) {
271265 * .then((collection) => console.log(collection))
272266 *
273267 */
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 )
294284 }
285+ } catch ( err ) {
286+ throw error ( err )
287+ }
288+ }
295289
296- /**
290+ /**
297291 * @description The Publish rule allow you to create, fetch, delete, update the publish rules.
298292 * @memberof Workflow
299293 * @func publishRule
@@ -305,25 +299,25 @@ export function Workflow (http, data = {}) {
305299 *
306300 * client.stack({ api_key: 'api_key'}).workflow().publishRule().fetchAll()
307301 * .then((collection) => console.log(collection))
308- *
302+ *
309303 * client.stack({ api_key: 'api_key'}).workflow().publishRule('rule_uid').fetch()
310304 * .then((publishrule) => console.log(publishrule))
311305 *
312306 */
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 )
320313 }
314+ }
321315}
322316
323317export 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