Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6d27d3a

Browse files
committedMay 17, 2021
fix: 🐛 Fix issue for Stack, webhook, and entry
- Resolved get all stack for org uid - Resolved Webhook fetch all issue - resolved entry fetch update issue
1 parent a2c80b3 commit 6d27d3a

File tree

6 files changed

+50
-116
lines changed

6 files changed

+50
-116
lines changed
 

‎lib/entity.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import error from './core/contentstackError'
22
import cloneDeep from 'lodash/cloneDeep'
33
import Query from './query/index'
4+
import ContentstackCollection from './contentstackCollection'
45

56
export const publish = (http, type) => {
67
return async function ({ publishDetails, locale = null, version = null, scheduledAt = null }) {
@@ -83,7 +84,7 @@ export const create = ({ http, params }) => {
8384
try {
8485
const response = await http.post(this.urlPath, data, headers)
8586
if (response.data) {
86-
return new this.constructor(http, parseData(response, this.stackHeaders))
87+
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid))
8788
} else {
8889
throw error(response)
8990
}
@@ -106,7 +107,7 @@ export const exportObject = ({ http }) => {
106107
try {
107108
const response = await http.get(this.urlPath, headers)
108109
if (response.data) {
109-
return new this.constructor(http, parseData(response, this.stackHeaders))
110+
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid))
110111
} else {
111112
throw error(response)
112113
}
@@ -215,6 +216,29 @@ export const fetch = (http, type) => {
215216
}
216217
}
217218
}
219+
export const fetchAll = (http, wrapperCollection) => {
220+
return async function (params = {}) {
221+
const headers = {}
222+
if (this.stackHeaders) {
223+
headers.headers = this.stackHeaders
224+
}
225+
if (params) {
226+
headers.params = {
227+
...cloneDeep(params)
228+
}
229+
}
230+
try {
231+
const response = await http.get(this.urlPath, headers)
232+
if (response.data) {
233+
return new ContentstackCollection(response, http, this.stackHeaders, wrapperCollection)
234+
} else {
235+
throw error(response)
236+
}
237+
} catch (err) {
238+
throw error(err)
239+
}
240+
}
241+
}
218242

219243
export function parseData (response, stackHeaders, contentTypeUID) {
220244
const data = response.data || {}

‎lib/organization/index.js

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cloneDeep from 'lodash/cloneDeep'
22
import error from '../core/contentstackError'
3-
import { fetch } from '../entity'
3+
import { fetch, fetchAll } from '../entity'
44
import ContentstackCollection from '../contentstackCollection'
55
import { RoleCollection } from '../stack/roles'
66
import { StackCollection } from '../stack'
@@ -222,25 +222,13 @@ export function Organization (http, data) {
222222
* .then((collection) => console.log(collection))
223223
*
224224
*/
225-
this.fetchAll = async (parmas) => {
226-
try {
227-
const response = await http.get(this.urlPath, { params: parmas })
228-
if (response.data) {
229-
return new ContentstackCollection(response, http, null, OrganizationCollection)
230-
} else {
231-
throw error(response)
232-
}
233-
} catch (err) {
234-
throw error(err)
235-
}
236-
}
225+
this.fetchAll = fetchAll(http, OrganizationCollection)
237226
}
238227
}
239228

240229
export function OrganizationCollection (http, data) {
241230
const obj = cloneDeep(data.organizations || [])
242-
const organizationCollection = obj.map((userdata) => {
231+
return obj.map((userdata) => {
243232
return new Organization(http, { organization: userdata })
244233
})
245-
return organizationCollection
246234
}

‎lib/stack/roles/index.js

+2-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cloneDeep from 'lodash/cloneDeep'
2-
import { create, update, deleteEntity, fetch, query } from '../../entity'
2+
import { create, update, deleteEntity, fetch, query, fetchAll } from '../../entity'
33
import ContentstackCollection from '../../contentstackCollection'
44
import error from '../../core/contentstackError'
55
/**
@@ -133,27 +133,7 @@ export function Role (http, data) {
133133
* client.stack().role().findAll()
134134
* .then((collection) => console.log(collection))
135135
*/
136-
this.fetchAll = async (params = {}) => {
137-
const headers = {}
138-
if (this.stackHeaders) {
139-
headers.headers = this.stackHeaders
140-
}
141-
if (params) {
142-
headers.params = {
143-
...cloneDeep(params)
144-
}
145-
}
146-
try {
147-
const response = await http.get(this.urlPath, headers)
148-
if (response.data) {
149-
return new ContentstackCollection(response, http, this.stackHeaders, RoleCollection)
150-
} else {
151-
throw error(response)
152-
}
153-
} catch (err) {
154-
throw error(err)
155-
}
156-
}
136+
this.fetchAll = fetchAll(http, RoleCollection)
157137

158138
/**
159139
* @description The Query on Role will allow to fetch details of all or specific role.

‎lib/stack/webhook/index.js

+3-22
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
deleteEntity,
66
fetch,
77
upload,
8-
parseData
8+
parseData,
9+
fetchAll
910
} from '../../entity'
1011
import error from '../../core/contentstackError'
1112
import FormData from 'form-data'
@@ -179,27 +180,7 @@ export function Webhook (http, data = {}) {
179180
* .then((collection) => console.log(collection))
180181
*
181182
*/
182-
this.fetchAll = async (params) => {
183-
const headers = {}
184-
if (this.stackHeaders) {
185-
headers.headers = this.stackHeaders
186-
}
187-
if (params) {
188-
headers.params = {
189-
...cloneDeep(params)
190-
}
191-
}
192-
try {
193-
const response = await http.get(this.urlPath, headers)
194-
if (response.data) {
195-
return new ContentstackCollection(response, http, null, WebhookCollection)
196-
} else {
197-
throw error(response)
198-
}
199-
} catch (err) {
200-
throw error(err)
201-
}
202-
}
183+
this.fetchAll = fetchAll(http, WebhookCollection)
203184
}
204185

205186
/**

‎lib/stack/workflow/index.js

+3-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
create,
44
update,
55
deleteEntity,
6-
fetch
6+
fetch,
7+
fetchAll
78
} from '../../entity'
89
import error from '../../core/contentstackError'
910
import ContentstackCollection from '../../contentstackCollection'
@@ -265,27 +266,7 @@ export function Workflow (http, data = {}) {
265266
* .then((collection) => console.log(collection))
266267
*
267268
*/
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)
284-
}
285-
} catch (err) {
286-
throw error(err)
287-
}
288-
}
269+
this.fetchAll = fetchAll(http, WorkflowCollection)
289270

290271
/**
291272
* @description The Publish rule allow you to create, fetch, delete, update the publish rules.

‎lib/stack/workflow/publishRules/index.js

+13-33
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
create,
44
update,
55
deleteEntity,
6-
fetch
6+
fetch,
7+
fetchAll
78
} from '../../../entity'
89
import error from '../../../core/contentstackError'
910
import 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

142122
export 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

Comments
 (0)
Please sign in to comment.