1
1
import { BaseCommand } from '../lib'
2
2
import { getEnvironment } from '../lib/environments'
3
3
import { flags } from '@oclif/command'
4
- import fetch from 'node-fetch'
5
4
import { cli } from 'cli-ux'
6
5
7
6
export default class UpdateBackend extends BaseCommand {
8
7
static description = 'Update Backend'
9
8
10
9
static examples = [
11
- '$ slash-graphql update-backend -n "New Name" 0xid ' ,
10
+ '$ slash-graphql update-backend -e 0xid - n "New Name" -m flexible ' ,
12
11
]
13
12
14
13
static flags = {
15
14
...BaseCommand . commonFlags ,
15
+ ...BaseCommand . endpointFlags ,
16
16
name : flags . string ( { char : 'n' , description : 'Name' } ) ,
17
17
organizationId : flags . string ( { char : 'o' , description : 'Organization UID' , default : '' } ) ,
18
18
confirm : flags . boolean ( { char : 'y' , description : 'Skip Confirmation' , default : false } ) ,
19
- 'deployment- mode' : flags . string ( { char : 'm' , description : 'Deployment Mode' , options : [ 'readonly' , 'graphql' , 'flexible' ] } ) ,
19
+ mode : flags . string ( { char : 'm' , description : 'Backend Mode' , options : [ 'readonly' , 'graphql' , 'flexible' ] } ) ,
20
20
}
21
21
22
- static args = [ { name : 'id' , description : 'Backend UID' , required : true } ]
23
-
24
22
confirm ( ) {
25
- this . log ( 'Depending on which properties you are updating, this may cause your cluster to restart. Your data will be preserved' )
23
+ this . log ( 'Depending on which properties you are updating, this may cause your backend to restart. Your data will be preserved' )
26
24
return cli . confirm ( 'Are you sure you want to proceed?' )
27
25
}
28
26
29
27
async run ( ) {
30
28
const opts = this . parse ( UpdateBackend )
31
29
const { apiServer, authFile} = getEnvironment ( opts . flags . environment )
30
+ const endpoint = await this . convertToGraphQLUid ( apiServer , authFile , opts . flags . endpoint ) || ''
32
31
33
32
const token = await this . getAccessToken ( apiServer , authFile )
34
33
if ( ! token ) {
@@ -39,8 +38,8 @@ export default class UpdateBackend extends BaseCommand {
39
38
if ( opts . flags . name ) {
40
39
updates . name = opts . flags . name
41
40
}
42
- if ( opts . flags [ 'deployment- mode' ] ) {
43
- updates . deploymentMode = opts . flags [ 'deployment- mode' ]
41
+ if ( opts . flags . mode ) {
42
+ updates . deploymentMode = opts . flags . mode
44
43
}
45
44
if ( opts . flags . organizationId ) {
46
45
updates . organizationId = opts . flags . organizationId
@@ -55,19 +54,10 @@ export default class UpdateBackend extends BaseCommand {
55
54
return
56
55
}
57
56
58
- const response = await fetch ( `${ apiServer } /deployment/${ opts . args . id } ` , {
59
- method : 'PATCH' ,
60
- headers : {
61
- 'Content-Type' : 'application/json' ,
62
- Authorization : `Bearer ${ token } ` ,
63
- } ,
64
- body : JSON . stringify ( updates ) ,
65
- } )
66
- if ( response . status !== 200 ) {
67
- this . error ( `Error while updating backend\n${ await response . text ( ) } ` )
68
- }
69
- if ( ! opts . flags . quiet ) {
70
- this . log ( 'Updated Backend' )
57
+ const { error, response} = await this . patchBackend ( apiServer , token , endpoint , updates )
58
+ if ( error ) {
59
+ this . error ( error )
71
60
}
61
+ this . log ( response . message )
72
62
}
73
63
}
0 commit comments