1- import cloneDeep from ' lodash/cloneDeep'
2- import { create , query , fetch , deleteEntity } from ' ../../entity'
3- import { Compare } from ' ./compare'
4- import { MergeQueue } from ' ./mergeQueue'
5- import error from ' ../../core/contentstackError'
1+ import cloneDeep from " lodash/cloneDeep" ;
2+ import { create , query , fetch , deleteEntity } from " ../../entity" ;
3+ import { Compare } from " ./compare" ;
4+ import { MergeQueue } from " ./mergeQueue" ;
5+ import error from " ../../core/contentstackError" ;
66
77/**
88 *
99 * @namespace Branch
1010 */
11- export function Branch ( http , data = { } ) {
12- this . stackHeaders = data . stackHeaders
13- this . urlPath = `/stacks/branches`
11+ export function Branch ( http , data = { } ) {
12+ this . stackHeaders = data . stackHeaders ;
13+ this . urlPath = `/stacks/branches` ;
1414
15- data . branch = data . branch || data . branch_alias
16- delete data . branch_alias
15+ data . branch = data . branch || data . branch_alias ;
16+ delete data . branch_alias ;
1717
1818 if ( data . branch ) {
19- Object . assign ( this , cloneDeep ( data . branch ) )
20- this . urlPath = `/stacks/branches/${ this . uid } `
19+ Object . assign ( this , cloneDeep ( data . branch ) ) ;
20+ this . urlPath = `/stacks/branches/${ this . uid } ` ;
2121
2222 /**
2323 * @description The Delete Branch call is used to delete an existing Branch permanently from your Stack.
@@ -31,7 +31,7 @@ export function Branch (http, data = {}) {
3131 * client.stack({ api_key: 'api_key'}).branch('branch_uid').delete()
3232 * .then((response) => console.log(response.notice))
3333 */
34- this . delete = deleteEntity ( http , true )
34+ this . delete = deleteEntity ( http , true ) ;
3535
3636 /**
3737 * @description The fetch Branch call fetches Branch details.
@@ -46,7 +46,7 @@ export function Branch (http, data = {}) {
4646 * .then((branch) => console.log(branch))
4747 *
4848 */
49- this . fetch = fetch ( http , ' branch' )
49+ this . fetch = fetch ( http , " branch" ) ;
5050
5151 /**
5252 * @description Compare allows you to compare any or specific ContentType or GlobalFields.
@@ -61,15 +61,39 @@ export function Branch (http, data = {}) {
6161 *
6262 */
6363 this . compare = ( compareBranchUid ) => {
64- const compareData = { stackHeaders : this . stackHeaders }
64+ const compareData = { stackHeaders : this . stackHeaders } ;
6565 if ( compareBranchUid ) {
6666 compareData . branches = {
6767 base_branch : this . uid ,
68- compare_branch : compareBranchUid
69- }
68+ compare_branch : compareBranchUid ,
69+ } ;
7070 }
71- return new Compare ( http , compareData )
72- }
71+ return new Compare ( http , compareData ) ;
72+ } ;
73+
74+ /**
75+ * @description The Update Branch Settings call updates the settings of an existing Branch.
76+ * @memberof Branch
77+ * @func updateSettings
78+ * @param {IBranchSettings } payload - The settings payload to update.
79+ * @returns {Promise<Object> } Response Object.
80+ * @example
81+ * import * as contentstack from '@contentstack/management'
82+ * const client = contentstack.client()
83+ * client.stack({ api_key: 'api_key' }).branch('branch_uid').updateSettings(payload)
84+ * .then((response) => console.log(response.notice))
85+ */
86+ this . updateSettings = async ( payload ) => {
87+ try {
88+ const response = await http . post ( `${ this . urlPath } /settings` , payload , {
89+ headers : { ...cloneDeep ( this . stackHeaders ) } ,
90+ } ) ;
91+ if ( response . data ) return response . data ;
92+ else throw error ( response ) ;
93+ } catch ( e ) {
94+ throw error ( e ) ;
95+ }
96+ } ;
7397 } else {
7498 /**
7599 * @description The Create a Branch call creates a new branch in a particular stack of your Contentstack account.
@@ -87,7 +111,7 @@ export function Branch (http, data = {}) {
87111 * client.stack({ api_key: 'api_key'}).branch().create({ branch })
88112 * .then((branch) => { console.log(branch) })
89113 */
90- this . create = create ( { http : http } )
114+ this . create = create ( { http : http } ) ;
91115
92116 /**
93117 * @description The 'Get all Branch' request returns comprehensive information about branches created in a Stack.
@@ -102,7 +126,7 @@ export function Branch (http, data = {}) {
102126 * client.stack({ api_key: 'api_key'}).branch().query().find()
103127 * .then((collection) => { console.log(collection) })
104128 */
105- this . query = query ( { http, wrapperCollection : BranchCollection } )
129+ this . query = query ( { http, wrapperCollection : BranchCollection } ) ;
106130
107131 /**
108132 * @description Merge allows user to merge branches in a Stack.
@@ -135,19 +159,19 @@ export function Branch (http, data = {}) {
135159 * client.stack({ api_key: 'api_key'}).branch().merge(mergeObj, params)
136160 */
137161 this . merge = async ( mergeObj , params ) => {
138- const url = ' /stacks/branches_merge'
162+ const url = " /stacks/branches_merge" ;
139163 const header = {
140164 headers : { ...cloneDeep ( this . stackHeaders ) } ,
141- params : params
142- }
165+ params : params ,
166+ } ;
143167 try {
144- const response = await http . post ( url , mergeObj , header )
145- if ( response . data ) return response . data
146- else throw error ( response )
168+ const response = await http . post ( url , mergeObj , header ) ;
169+ if ( response . data ) return response . data ;
170+ else throw error ( response ) ;
147171 } catch ( e ) {
148- throw error ( e )
172+ throw error ( e ) ;
149173 }
150- }
174+ } ;
151175
152176 /**
153177 * @description Merge Queue provides list of all recent merge jobs in a Stack.
@@ -163,16 +187,19 @@ export function Branch (http, data = {}) {
163187 *
164188 */
165189 this . mergeQueue = ( uid ) => {
166- const mergeData = { stackHeaders : this . stackHeaders , uid }
167- return new MergeQueue ( http , mergeData )
168- }
190+ const mergeData = { stackHeaders : this . stackHeaders , uid } ;
191+ return new MergeQueue ( http , mergeData ) ;
192+ } ;
169193 }
170- return this
194+ return this ;
171195}
172196
173- export function BranchCollection ( http , data ) {
174- const obj = cloneDeep ( data . branches ) || data . branch_aliases || [ ]
197+ export function BranchCollection ( http , data ) {
198+ const obj = cloneDeep ( data . branches ) || data . branch_aliases || [ ] ;
175199 return obj . map ( ( branchData ) => {
176- return new Branch ( http , { branch : branchData , stackHeaders : data . stackHeaders } )
177- } )
200+ return new Branch ( http , {
201+ branch : branchData ,
202+ stackHeaders : data . stackHeaders ,
203+ } ) ;
204+ } ) ;
178205}
0 commit comments