Skip to content

Commit

Permalink
All remaining functionality is tested
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfoul committed Aug 19, 2016
1 parent 655b551 commit 9d777e4
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 205 deletions.
20 changes: 14 additions & 6 deletions node/DataContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,22 @@ export abstract class DataContract implements IDataContract {
}

public save(): Promise<this> {
return this.internalSave(true);
}

public internalSave(saveRelated: boolean): Promise<this> {
if (this.instance) {
return this.instance.save()
.then(this.saveRelated.bind(this))
.then(() => this);
let ret = this.instance.save();
if (saveRelated) {
ret = ret.then(this.saveRelated.bind(this));
}
return ret.then(() => this);
} else {
return (<DataContractType> this.constructor)
.getSequelizeModel()
.then(this.saveRelated.bind(this))
let ret = (<DataContractType> this.constructor).getSequelizeModel();
if (saveRelated) {
ret = ret.then(this.saveRelated.bind(this));
}
return ret
.then((model: sequelize.Model<any, any>) => {
return model.create(this.getFields(getFieldsSources.save));
})
Expand Down
Loading

0 comments on commit 9d777e4

Please sign in to comment.