Skip to content

Commit fc377fb

Browse files
committed
Add rollbackAttributes() method to model
1 parent a38fa1c commit fc377fb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/models/json-api.model.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ export class JsonApiModel {
4343
return hasDirtyAttributes;
4444
}
4545

46+
rollbackAttributes() {
47+
let attributesMetadata = Reflect.getMetadata('Attribute', this);
48+
let metadata: any;
49+
for (let propertyName in attributesMetadata) {
50+
if (attributesMetadata.hasOwnProperty(propertyName)) {
51+
if (attributesMetadata[propertyName].hasDirtyAttributes) {
52+
this[propertyName] = attributesMetadata[propertyName].oldValue;
53+
metadata = {
54+
hasDirtyAttributes: false,
55+
newValue: attributesMetadata[propertyName].oldValue,
56+
oldValue: undefined
57+
};
58+
attributesMetadata[propertyName] = metadata;
59+
}
60+
}
61+
}
62+
Reflect.defineMetadata('Attribute', attributesMetadata, this);
63+
}
64+
4665
private parseHasMany(data: any, included: any, level: number) {
4766
let hasMany = Reflect.getMetadata('HasMany', this);
4867
if (hasMany) {

0 commit comments

Comments
 (0)