Skip to content

Commit

Permalink
Fixes the typescript lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
lygstate committed Oct 10, 2016
1 parent 1246a3e commit 9b80ce5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
1 change: 1 addition & 0 deletions lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ module.exports = function generate(ctx) {
{ module: 'LoopBackAuth', from: './auth.service'},
{ module: 'LoopBackConfig', from: '../../lb.config'},
{ module: 'AccessToken', from: '../../models'},
{ module: 'Observable', from: 'rxjs/Observable' },
{ module: 'ErrorObservable', from: 'rxjs/observable/ErrorObservable' },
{ module: 'rxjs/add/operator/catch' },
{ module: 'rxjs/add/operator/map' },
Expand Down
67 changes: 33 additions & 34 deletions lib/angular2/shared/services/core/base.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export abstract class BaseLoopBackApi {
protected path: string;

constructor(
@Inject(Http) protected http: Http,
@Inject(LoopBackAuth) protected auth: LoopBackAuth,
@Inject(JSONSearchParams) protected searchParams: JSONSearchParams,
@Inject(Http) protected http: Http,
@Inject(LoopBackAuth) protected auth: LoopBackAuth,
@Inject(JSONSearchParams) protected searchParams: JSONSearchParams,
@Optional() @Inject(ErrorHandler) protected errorHandler: ErrorHandler
) {}

Expand All @@ -37,11 +37,9 @@ export abstract class BaseLoopBackApi {
url : string,
routeParams : any = {},
urlParams : any = {},
postBody : any = null<% if ( isIo === 'enabled' ){ -%>,
isio : boolean = false<% }
-%>

) {
postBody : any = null,
isio : boolean = false
): Observable<any> {

let headers = new Headers();
headers.append('Content-Type', 'application/json');
Expand All @@ -61,8 +59,8 @@ export abstract class BaseLoopBackApi {
routeParams[key] + "$1"
);
}

<% if ( isIo === 'enabled' ){ -%>
if (isio) {
if (requestUrl.match(/fk/)) {
let arr = requestUrl.split('/'); arr.pop();
Expand All @@ -76,30 +74,31 @@ export abstract class BaseLoopBackApi {
let socket: any = SocketConnections.getHandler(LoopBackConfig.getPath(), token);
socket.on(event, (res: any) => subject.next(res));
return subject.asObservable();
} else {<% } -%>
// Body fix for built in remote methods using "data", "options" or "credentials
// that are the actual body, Custom remote method properties are different and need
// to be wrapped into a body object
let body: any;
let postBodyKeys = typeof postBody === 'object' ? Object.keys(postBody) : []
if (postBodyKeys.length === 1) {
body = postBody[postBodyKeys[0]]
} else {
body = postBody;
}
this.searchParams.setJSON(urlParams);
let request: Request = new Request({
headers : headers,
method : method,
url : urlParams.filter ? `${requestUrl}?filter=${ encodeURI(JSON.stringify(urlParams.filter))}`
: requestUrl,
search : !urlParams.filter && Object.keys(urlParams).length > 0
? this.searchParams.getURLSearchParams() : null,
body : body ? JSON.stringify(body) : undefined
});
return this.http.request(request)
.map((res: any) => (res.text() != "" ? res.json() : {}))
.catch(this.errorHandler.handleError);
<% if ( isIo === 'enabled' ){ -%> }<% } -%>
}
<% } -%>

// Body fix for built in remote methods using "data", "options" or "credentials
// that are the actual body, Custom remote method properties are different and need
// to be wrapped into a body object
let body: any;
let postBodyKeys = typeof postBody === 'object' ? Object.keys(postBody) : []
if (postBodyKeys.length === 1) {
body = postBody[postBodyKeys[0]]
} else {
body = postBody;
}
this.searchParams.setJSON(urlParams);
let request: Request = new Request({
headers : headers,
method : method,
url : urlParams.filter ? `${requestUrl}?filter=${ encodeURI(JSON.stringify(urlParams.filter))}`
: requestUrl,
search : !urlParams.filter && Object.keys(urlParams).length > 0
? this.searchParams.getURLSearchParams() : null,
body : body ? JSON.stringify(body) : undefined
});
return this.http.request(request)
.map((res: any) => (res.text() != "" ? res.json() : {}))
.catch(this.errorHandler.handleError);
}
}
3 changes: 2 additions & 1 deletion lib/angular2/shared/services/core/error.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
import 'rxjs/add/observable/throw';
/**
* Default error handler
*/
@Injectable()
export class ErrorHandler {
public handleError(error: Response) {
public handleError(error: Response) :ErrorObservable {
return Observable.throw(error.json().error || 'Server error');
}
}

0 comments on commit 9b80ce5

Please sign in to comment.