Skip to content

Commit f52e87d

Browse files
committed
Merge branch 'bug/orgs-stack-and-entry-fetch' into feature/content-branching
2 parents 67edbb2 + 6d27d3a commit f52e87d

File tree

6 files changed

+48
-115
lines changed

6 files changed

+48
-115
lines changed

lib/entity.js

Lines changed: 26 additions & 2 deletions
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
}
@@ -224,6 +225,29 @@ export const fetch = (http, type) => {
224225
}
225226
}
226227
}
228+
export const fetchAll = (http, wrapperCollection) => {
229+
return async function (params = {}) {
230+
const headers = {}
231+
if (this.stackHeaders) {
232+
headers.headers = this.stackHeaders
233+
}
234+
if (params) {
235+
headers.params = {
236+
...cloneDeep(params)
237+
}
238+
}
239+
try {
240+
const response = await http.get(this.urlPath, headers)
241+
if (response.data) {
242+
return new ContentstackCollection(response, http, this.stackHeaders, wrapperCollection)
243+
} else {
244+
throw error(response)
245+
}
246+
} catch (err) {
247+
throw error(err)
248+
}
249+
}
250+
}
227251

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

lib/organization/index.js

Lines changed: 3 additions & 15 deletions
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

Lines changed: 2 additions & 22 deletions
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

Lines changed: 3 additions & 22 deletions
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

Lines changed: 3 additions & 22 deletions
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

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import {
33
create,
44
update,
55
deleteEntity,
6-
fetch
6+
fetch,
7+
fetchAll
78
} from '../../../entity'
8-
import error from '../../../core/contentstackError'
9-
import ContentstackCollection from '../../../contentstackCollection'
109

1110
/**
1211
* PublishRules is a tool that allows you to streamline the process of content creation and publishing, and lets you manage the content lifecycle of your project smoothly. Read more about <a href='https://www.contentstack.com/docs/developers/set-up-publish ruless-and-publish-rules'>PublishRuless and Publish Rules</a>.
@@ -80,17 +79,17 @@ export function PublishRules (http, data = {}) {
8079
* import * as contentstack from '@contentstack/management'
8180
* const client = contentstack.client()
8281
* const publishing_rule = {
83-
* "publish rules": "publish rules_uid",
82+
* "publish rules": "publish rules_uid",
8483
* "actions": [],
8584
* "content_types": ["$all"],
8685
* "locales": ["en-us"],
8786
* "environment": "environment_uid",
88-
* "approvers": {
89-
* "users": ["user_uid"],
90-
* "roles": ["role_uid"]
87+
* "approvers": {
88+
* "users": ["user_uid"],
89+
* "roles": ["role_uid"]
9190
* },
9291
* "publish rules_stage": "publish rules_stage_uid",
93-
* "disable_approver_publishing": false
92+
* "disable_approver_publishing": false
9493
* }
9594
* client.stack().publishRules().create({ publishing_rule })
9695
* .then((publishRules) => console.log(publishRules))
@@ -102,9 +101,9 @@ export function PublishRules (http, data = {}) {
102101
* @memberof Publish Rules
103102
* @func fetchAll
104103
* @param {String} content_types Enter a comma-separated list of content type UIDs for filtering publish rules on its basis.
105-
* @param {Int} limit The limit parameter will return a specific number of Publish Ruless in the output.
106-
* @param {Int} skip The skip parameter will skip a specific number of Publish Ruless in the output.
107-
* @param {Boolean}include_count To retrieve the count of Publish Ruless.
104+
* @param {Int} limit The limit parameter will return a specific number of Publish Rules in the output.
105+
* @param {Int} skip The skip parameter will skip a specific number of Publish Rules in the output.
106+
* @param {Boolean}include_count To retrieve the count of Publish Rules.
108107
* @returns {ContentstackCollection} Result collection of content of specified module.
109108
* @example
110109
* import * as contentstack from '@contentstack/management'
@@ -114,27 +113,7 @@ export function PublishRules (http, data = {}) {
114113
* .then((collection) => console.log(collection))
115114
*
116115
*/
117-
this.fetchAll = async (params) => {
118-
const headers = {}
119-
if (this.stackHeaders) {
120-
headers.headers = this.stackHeaders
121-
}
122-
if (params) {
123-
headers.params = {
124-
...cloneDeep(params)
125-
}
126-
}
127-
try {
128-
const response = await http.get(this.urlPath, headers)
129-
if (response.data) {
130-
return new ContentstackCollection(response, http, null, PublishRulesCollection)
131-
} else {
132-
throw error(response)
133-
}
134-
} catch (err) {
135-
throw error(err)
136-
}
137-
}
116+
this.fetchAll = fetchAll(http, PublishRulesCollection)
138117
}
139118
}
140119

0 commit comments

Comments
 (0)