@@ -132,9 +132,10 @@ export class Resource implements ICacheable {
132132
133133 // just for performance dont copy if not necessary
134134 let attributes : any ;
135- if ( this . getService ( ) && this . getService ( ) . parseToServer ) {
135+ let service : Service | undefined = this . getServiceOrUndefined ( ) ;
136+ if ( service && service . parseToServer ) {
136137 attributes = { ...{ } , ...this . attributes } ;
137- this . getService ( ) . parseToServer ( attributes ) ;
138+ service . parseToServer ( attributes ) ;
138139 } else {
139140 attributes = this . attributes ;
140141 }
@@ -167,6 +168,7 @@ export class Resource implements ICacheable {
167168
168169 public fill ( data_object : IDocumentResource | ICacheableDocumentResource ) : boolean {
169170 this . id = data_object . data . id || '' ;
171+ this . type = data_object . data . type || '' ;
170172
171173 // WARNING: leaving previous line for a tiem because this can produce undesired behavior
172174 // this.attributes = data_object.data.attributes || this.attributes;
@@ -283,6 +285,13 @@ export class Resource implements ICacheable {
283285 return Converter . getServiceOrFail ( this . type ) ;
284286 }
285287
288+ /*
289+ @return This resource like a service or undefined if not registered
290+ */
291+ public getServiceOrUndefined ( ) : Service | undefined {
292+ return Converter . getService ( this . type ) ;
293+ }
294+
286295 public delete ( ) : Observable < void > {
287296 return this . getService ( ) . delete ( this . id ) ;
288297 }
0 commit comments