Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
refactor(vm-creation): use post for vm deploy (#1491)
Browse files Browse the repository at this point in the history
PR Close #1491
  • Loading branch information
dron8552 committed Feb 4, 2019
2 parents 753fcbc + 71afa5c commit 1af663e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/app/shared/services/base-backend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ export abstract class BaseBackendService<M> {
return result[responseKeys[0]];
}

protected postRequest(command: string, params?: {}): Observable<any> {
protected postRequest(command: string, params?: {}, entity?: string): Observable<any> {
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');
return this.http.post(BACKEND_API_URL, this.buildParams(command, params), { headers });
return this.http.post(BACKEND_API_URL, this.buildParams(command, params, entity), { headers });
}

protected sendCommand(command: string, params?: {}, entity?: string): Observable<any> {
Expand All @@ -195,6 +195,13 @@ export abstract class BaseBackendService<M> {
);
}

protected sendPostCommand(command: string, params?: {}, entity?: string): Observable<any> {
return this.postRequest(command, params, entity).pipe(
map(res => this.getResponse(res)),
catchError(e => this.handleCommandError(e.error)),
);
}

protected handleCommandError(error): Observable<any> {
return throwError(ErrorService.parseError(this.getResponse(error)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/vm/shared/vm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class VmService extends BaseBackendService<VirtualMachine> {
}

public deploy(params: {}): Observable<any> {
return this.sendCommand(CSCommands.Deploy, params);
return this.sendPostCommand(CSCommands.Deploy, params);
}

public command(vm: VirtualMachine, command: string, params?: {}): Observable<VirtualMachine> {
Expand Down

0 comments on commit 1af663e

Please sign in to comment.