@@ -34,7 +34,7 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
3434 ngdocForMethod (modelName, methodName, action, httpVerb, fullPath);
3535
3636 if (methodName === ' createChangeStream' ) { -% >
37- public createChangeStream () {
37+ public createChangeStream (): Observable < any > {
3838 let url: string = LoopBackConfig .getPath () + " /" + LoopBackConfig .getApiVersion () +
3939 < %- : fullPath | q % > ;
4040 let subject = new Subject ();
@@ -68,7 +68,7 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
6868 return (param .http && param .http .source === ' path' ) || (param .arg && param .arg .match (/ (id| fk| file| container)/ ));
6969 });
7070-% >
71- public < %- normalizeMethodName (methodName) % > (< %- buildMethodParams (model, methodName, action .accepts ) % > ) {
71+ public < %- normalizeMethodName (methodName) % > (< %- buildMethodParams (model, methodName, action .accepts ) % > ): Observable << %- buildObservableType (modelName, methodName) % >> {
7272 let method: string = < %- : httpVerb | q % > ;
7373 let url: string = LoopBackConfig .getPath () + " /" + LoopBackConfig .getApiVersion () +
7474 < %- : fullPath | q % > ;
@@ -92,7 +92,7 @@ if (model.isUser && methodName === 'login') { %>
9292 );
9393 return result;
9494 < %
95- } else if (methodName .match (/ (^ create$ | upsert| findById| findOne)/ g )) { % > ;
95+ } else if (methodName .match (/ (^ create$ | upsert| ^ findById$ | ^ findOne$ )/ g )) { % > ;
9696 return result .map ((instance : < %- modelName % > ) => new < %- : modelName % > (instance));< %
9797} else if (methodName .match (/ (^ createMany$ | ^ find)/ g )) { % > ;
9898 return result .map ((instances : Array << %- modelName % >> ) =>
@@ -110,15 +110,24 @@ if (model.isUser && methodName === 'login') { %>
110110 httpVerb !== ' HEAD' ){
111111-% >
112112
113- public on< %- normalizeMethodName (methodName, true ) % > (< %- buildMethodParams (model, methodName, action .accepts , true ) % > ) {
113+ public on< %- normalizeMethodName (methodName, true ) % > (< %- buildMethodParams (model, methodName, action .accepts , true ) % > ): Observable << %- buildObservableType (modelName, methodName) % >> {
114114 let method: string = < %- : httpVerb | q % > ;
115115 let url: string = " /" + LoopBackConfig .getApiVersion () +
116116 < %- : fullPath | q % > ;
117117 let routeParams: any = {< %- buildRouteParams (routeParams .filter (function (param ) { return param .arg !== ' fk' ; })) % > };
118118 let postBody: any = {};
119119 let urlParams: any = {};
120120 let result = this .request (method, url, routeParams, urlParams, postBody, true );
121- return result;
121+ < %
122+ if (methodName .match (/ (^ create$ | upsert| ^ findById$ | ^ findOne$ )/ g )) { % >
123+ return result .map ((instance : < %- modelName % > ) => new < %- : modelName % > (instance));< %
124+ } else if (methodName .match (/ (^ createMany$ | ^ find)/ g )) { % > ;
125+ return result .map ((instances : Array << %- modelName % >> ) =>
126+ instances .map ((instance : < %- modelName % > ) => new < %- : modelName % > (instance))
127+ );< %
128+ } else { % > ;
129+ return result;< %
130+ } % >
122131 }
123132< % }} -% >
124133< % }); // model.methods.foreach -%>
0 commit comments