Skip to content

Commit 5eedd8d

Browse files
authored
Merge pull request #16 from contentstack/bug/orgs-stack-and-entry-fetch
Bug/orgs stack and entry fetch
2 parents db45a95 + 2d5c851 commit 5eedd8d

File tree

11 files changed

+149
-179
lines changed

11 files changed

+149
-179
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# Changelog
2+
3+
## [v1.2.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.2.2) (2021-05-26)
4+
- Bug Fix
5+
- Organization Specific get all Stack: Get Stack for specific organization from org_uid
6+
- Resolved: Entry Publish and Update not work after find function
7+
- Resolved: Workflow update issue on fetchAll function
8+
- Document Update
9+
- `update` Entry example code update
10+
211
## [v1.2.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.2.1) (2021-03-19)
312
- Bug Fix
413
- User get details: Include organization functions for `is_owner` of the organization

lib/contentstack.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import httpClient from './core/contentstackHTTPClient.js'
4444
* import * as contentstack from '@contentstack/management'
4545
* const client = contentstack.client({ maxRequests: 5 })
4646
*
47-
* @prop {boolean=} params.retryOnError - Optional boolean for retry on failuer. Default is true
47+
* @prop {boolean=} params.retryOnError - Optional boolean for retry on failure. Default is true
4848
* @example //Set the `retryOnError` to false
4949
* import * as contentstack from '@contentstack/management'
5050
* const client = contentstack.client({ retryOnError: false })
@@ -54,7 +54,7 @@ import httpClient from './core/contentstackHTTPClient.js'
5454
* import * as contentstack from '@contentstack/management'
5555
* const client = contentstack.client({ retryLimit: 2 })
5656
*
57-
* @prop {number=} params.retryDelay - The number of miliseconds to use for operation retries. Default is 300ms
57+
* @prop {number=} params.retryDelay - The number of milliseconds to use for operation retries. Default is 300ms
5858
* @example //Set the `retryDelay` to 500ms
5959
* import * as contentstack from '@contentstack/management'
6060
* const client = contentstack.client({ retryDelay: 500 })
@@ -93,7 +93,7 @@ import httpClient from './core/contentstackHTTPClient.js'
9393
* const client = contentstack.client({ maxContentLength: 1024 ** 3 })
9494
*
9595
* @prop {number=} params.maxBodyLength - Optional maximum body length in bytes (default: 10 MB)
96-
* @example //Set the `maxContentLength` to 1024 ** 2 * 10 // 10 MB
96+
* @example //Set the `maxBodyLength` to 1024 ** 2 * 10 // 10 MB
9797
* import * as contentstack from '@contentstack/management'
9898
* const client = contentstack.client({ maxBodyLength: 1024 ** 2 * 10 })
9999
*

lib/entity.js

+33-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
}
@@ -119,8 +120,15 @@ export const exportObject = ({ http }) => {
119120
export const query = ({ http, wrapperCollection }) => {
120121
return function (params = {}) {
121122
if (this.organization_uid) {
123+
if (!params.query) {
124+
params.query = {}
125+
}
122126
params.query['org_uid'] = this.organization_uid
123127
}
128+
129+
if (this.content_type_uid) {
130+
params.content_type_uid = this.content_type_uid
131+
}
124132
return Query(http, this.urlPath, params, this.stackHeaders, wrapperCollection)
125133
}
126134
}
@@ -208,6 +216,29 @@ export const fetch = (http, type) => {
208216
}
209217
}
210218
}
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+
}
211242

212243
export function parseData (response, stackHeaders, contentTypeUID) {
213244
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/query/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ export default function Query (http, urlPath, param, stackHeaders = null, wrappe
77
if (stackHeaders) {
88
headers.headers = stackHeaders
99
}
10+
var contentTypeUid = null
1011
if (param) {
12+
if (param.content_type_uid) {
13+
contentTypeUid = param.content_type_uid
14+
delete param.content_type_uid
15+
}
1116
headers.params = {
1217
...cloneDeep(param)
1318
}
@@ -34,6 +39,9 @@ export default function Query (http, urlPath, param, stackHeaders = null, wrappe
3439
try {
3540
const response = await http.get(urlPath, headers)
3641
if (response.data) {
42+
if (contentTypeUid) {
43+
response.data.content_type_uid = contentTypeUid
44+
}
3745
return new ContentstackCollection(response, http, stackHeaders, wrapperCollection)
3846
} else {
3947
throw error(response)
@@ -100,6 +108,9 @@ export default function Query (http, urlPath, param, stackHeaders = null, wrappe
100108
try {
101109
const response = await http.get(urlPath, limitHeader)
102110
if (response.data) {
111+
if (contentTypeUid) {
112+
response.data.content_type_uid = contentTypeUid
113+
}
103114
return new ContentstackCollection(response, http, stackHeaders, wrapperCollection)
104115
} else {
105116
throw error(response)

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)