11import cloneDeep from 'lodash/cloneDeep'
22import error from '../../core/contentstackError'
33
4- export function Request ( http , data , param ) {
4+ export function AppRequest ( http , data , param ) {
55 http . defaults . versioningStrategy = undefined
6- this . urlPath = '/manifests'
76 this . params = param || { }
87
98 if ( data ) {
@@ -13,20 +12,20 @@ export function Request (http, data, param) {
1312 }
1413 }
1514 /**
16- * @description The Delete app request call is used to delete an app request of an app in target_uid.
17- * @param {string } requestUID The ID of the request to be deleted
18- * @returns Promise<Response>
19- * @memberof Request
20- * @func delete
21- *
22- * @example
23- * import * as contentstack from '@contentstack/management'
24- * const client = contentstack.client({ authtoken: 'TOKEN'})
25- *
26- * client.organization('organization_uid').app( ).request().delete('request_uid`)
27- * .then((response) => console.log(response))
28- *
29- */
15+ * @description The Delete app request call is used to delete an app request of an app in target_uid.
16+ * @param {string } requestUID The ID of the request to be deleted
17+ * @returns Promise<Response>
18+ * @memberof AppRequest
19+ * @func delete
20+ *
21+ * @example
22+ * import * as contentstack from '@contentstack/management'
23+ * const client = contentstack.client({ authtoken: 'TOKEN'})
24+ *
25+ * client.organization('organization_uid').request().delete('request_uid`)
26+ * .then((response) => console.log(response))
27+ *
28+ */
3029 this . delete = async ( requestUid ) => {
3130 try {
3231 const headers = {
@@ -43,101 +42,68 @@ export function Request (http, data, param) {
4342 throw error ( err )
4443 }
4544 }
46- if ( data . app_uid ) {
47- /**
48- * @description The Create installation call is used to create a app request for an app.
49- * @param {string } targetUid The uid of the target, on which the app will be installed
50- * @returns Promise<Response>
51- * @memberof Request
52- * @func create
53- *
54- * @example
55- * import * as contentstack from '@contentstack/management'
56- * const client = contentstack.client({ authtoken: 'TOKEN'})
57- *
58- * client.organization('organization_uid').app('app_uid').request().create('target_uid')
59- * .then((response) => console.log(response))
60- *
61- */
62- this . create = async ( targetUid ) => {
63- try {
64- const headers = {
65- headers : { ...cloneDeep ( this . params ) }
66- }
67-
68- const response = await http . post ( `/requests` , { app_uid : data . app_uid , target_uid : targetUid } , headers )
69- if ( response . data ) {
70- return response . data
71- } else {
72- throw error ( response )
73- }
74- } catch ( err ) {
75- throw error ( err )
45+ /**
46+ * @description The Create call is used to create a app request for an app.
47+ * @param {string } appUid The uid for the app for request
48+ * @param {string } targetUid The uid of the target, on which the app will be installed
49+ * @returns Promise<Response>
50+ * @memberof AppRequest
51+ * @func create
52+ *
53+ * @example
54+ * import * as contentstack from '@contentstack/management'
55+ * const client = contentstack.client({ authtoken: 'TOKEN'})
56+ *
57+ * client.organization('organization_uid').request().create({ appUid: 'app_uid', targetUid: 'target_uid' })
58+ * .then((response) => console.log(response))
59+ *
60+ */
61+ this . create = async ( { appUid, targetUid } ) => {
62+ try {
63+ const headers = {
64+ headers : { ...cloneDeep ( this . params ) }
7665 }
77- }
7866
79- /**
80- * @description The GET app requests of an app call is used to retrieve all requests of an app.
81- * @returns Promise<Response>
82- * @memberof Request
83- * @func fetch
84- *
85- * @example
86- * import * as contentstack from '@contentstack/management'
87- * const client = contentstack.client({ authtoken: 'TOKEN'})
88- *
89- * client.organization('organization_uid').app('app_uid').request().fetch()
90- * .then((response) => console.log(response))
91- *
92- */
93- this . fetch = async ( ) => {
94- try {
95- const headers = {
96- headers : { ...cloneDeep ( this . params ) }
97- }
98-
99- const response = await http . get ( `/manifests/${ data . app_uid } /requests` , headers )
100- if ( response . data ) {
101- return response . data
102- } else {
103- throw error ( response )
104- }
105- } catch ( err ) {
106- throw error ( err )
67+ const response = await http . post ( `/requests` , { app_uid : appUid , target_uid : targetUid } , headers )
68+ if ( response . data ) {
69+ return response . data
70+ } else {
71+ throw error ( response )
10772 }
73+ } catch ( err ) {
74+ throw error ( err )
10875 }
109- } else {
110- /**
111- * @description The GET all app requests call is used to retrieve all requests of all apps in an organization.
112- * @param {object } param object for query params
113- * @returns Promise<Response>
114- * @memberof Request
115- * @func findAll
116- *
117- * @example
118- * import * as contentstack from '@contentstack/management'
119- * const client = contentstack.client({ authtoken: 'TOKEN'})
120- *
121- * client.organization('organization_uid').app('app_uid ').request().findAll()
122- * .then((response) => console.log(response))
123- *
124- */
125- this . findAll = async ( param = { } ) => {
126- try {
127- const headers = {
128- headers : { ...cloneDeep ( this . params ) } ,
129- params : { ...param }
130- }
76+ }
77+ /**
78+ * @description The GET all app requests call is used to retrieve all requests of all apps in an organization.
79+ * @param {object } param object for query params
80+ * @returns Promise<Response>
81+ * @memberof AppRequest
82+ * @func findAll
83+ *
84+ * @example
85+ * import * as contentstack from '@contentstack/management'
86+ * const client = contentstack.client({ authtoken: 'TOKEN'})
87+ *
88+ * client.organization('organization_uid').request().findAll()
89+ * .then((response) => console.log(response))
90+ *
91+ */
92+ this . findAll = async ( param = { } ) => {
93+ try {
94+ const headers = {
95+ headers : { ...cloneDeep ( this . params ) } ,
96+ params : { ...param }
97+ }
13198
132- const response = await http . get ( `/requests` , headers )
133- if ( response . data ) {
134- return response . data
135- } else {
136- throw error ( response )
137- }
138- } catch ( err ) {
139- throw error ( err )
99+ const response = await http . get ( `/requests` , headers )
100+ if ( response . data ) {
101+ return response . data
102+ } else {
103+ throw error ( response )
140104 }
105+ } catch ( err ) {
106+ throw error ( err )
141107 }
142108 }
143109 }
0 commit comments