Skip to content

Commit

Permalink
Add rollbackAttributes() method to model
Browse files Browse the repository at this point in the history
  • Loading branch information
ghidoz committed Sep 18, 2016
1 parent a38fa1c commit fc377fb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/models/json-api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ export class JsonApiModel {
return hasDirtyAttributes;
}

rollbackAttributes() {
let attributesMetadata = Reflect.getMetadata('Attribute', this);
let metadata: any;
for (let propertyName in attributesMetadata) {
if (attributesMetadata.hasOwnProperty(propertyName)) {
if (attributesMetadata[propertyName].hasDirtyAttributes) {
this[propertyName] = attributesMetadata[propertyName].oldValue;
metadata = {
hasDirtyAttributes: false,
newValue: attributesMetadata[propertyName].oldValue,
oldValue: undefined
};
attributesMetadata[propertyName] = metadata;
}
}
}
Reflect.defineMetadata('Attribute', attributesMetadata, this);
}

private parseHasMany(data: any, included: any, level: number) {
let hasMany = Reflect.getMetadata('HasMany', this);
if (hasMany) {
Expand Down

0 comments on commit fc377fb

Please sign in to comment.