@@ -35,7 +35,7 @@ export class CrudService {
35
35
/** Gives true if the given change fits all property values of the filter. */
36
36
matches ( change : Update , filter : Update ) : boolean {
37
37
return Object . keys ( filter )
38
- . reduce ( ( match , key ) => match && change [ key ] === filter [ key ] , true ) ;
38
+ . reduce ( ( match , key ) => match && change [ key ] === filter [ key ] , true ) ;
39
39
}
40
40
41
41
/** Yields an observable that emits for all updates that match the given filter */
@@ -52,11 +52,11 @@ export class CrudService {
52
52
return this . update ( model , entry , value ) ;
53
53
}
54
54
return this . create ( model , value )
55
- . then ( ( _entry ) => {
56
- return _entry ;
57
- } ) . catch ( ( err ) => {
58
- return Promise . reject ( err ) ;
59
- } ) ;
55
+ . then ( ( _entry ) => {
56
+ return _entry ;
57
+ } ) . catch ( ( err ) => {
58
+ return Promise . reject ( err ) ;
59
+ } ) ;
60
60
}
61
61
62
62
/** Updates the given entry with the new value. Fires the "update" change. */
@@ -68,10 +68,10 @@ export class CrudService {
68
68
this . changes . next ( { model, entry : _entry , type : 'put' } ) ;
69
69
return _entry ;
70
70
} )
71
- . catch ( ( err ) => {
72
- Object . assign ( entry , this . clean ( oldValues ) ) ; // fall back to old values
73
- return Promise . reject ( err ) ;
74
- } ) ;
71
+ . catch ( ( err ) => {
72
+ Object . assign ( entry , this . clean ( oldValues ) ) ; // fall back to old values
73
+ return Promise . reject ( err ) ;
74
+ } ) ;
75
75
}
76
76
77
77
/** Returns true if the given field key is an immutable system property */
@@ -83,11 +83,13 @@ export class CrudService {
83
83
/** Removes all null or undefined values from the given object */
84
84
clean ( value : Object ) : Object {
85
85
for ( const key in value ) {
86
- if ( value [ key ] === '' ) { // clear empty strings
87
- value [ key ] = null ;
88
- }
89
- if ( this . isImmutableProperty ( key ) ) { // filter system properties
90
- delete value [ key ] ;
86
+ if ( value . hasOwnProperty ( key ) ) {
87
+ if ( value [ key ] === '' ) { // clear empty strings
88
+ value [ key ] = null ;
89
+ }
90
+ if ( this . isImmutableProperty ( key ) ) { // filter system properties
91
+ delete value [ key ] ;
92
+ }
91
93
}
92
94
}
93
95
return value ;
@@ -96,14 +98,14 @@ export class CrudService {
96
98
/** Creates a new entry with the given value for the given model. Fires the "create" change. */
97
99
create ( model : string , value : Object ) : Promise < EntryResource > {
98
100
return this . sdk . api . createEntry ( model , this . clean ( value ) )
99
- . then ( ( entry ) => {
100
- // console.log('created entry', entry);
101
- // TODO make sure leveled entries are returned leveled
102
- this . changes . next ( { model, entry, type : 'post' } ) ;
103
- return entry ;
104
- } ) . catch ( ( err ) => {
105
- return Promise . reject ( err ) ;
106
- } ) ;
101
+ . then ( ( entry ) => {
102
+ // console.log('created entry', entry);
103
+ // TODO make sure leveled entries are returned leveled
104
+ this . changes . next ( { model, entry, type : 'post' } ) ;
105
+ return entry ;
106
+ } ) . catch ( ( err ) => {
107
+ return Promise . reject ( err ) ;
108
+ } ) ;
107
109
}
108
110
109
111
/** deletes the given entry and emits the "delete" change. */
0 commit comments