Skip to content

Commit

Permalink
fix(types): add isSoftDeleted to Model
Browse files Browse the repository at this point in the history
  • Loading branch information
todd committed Nov 4, 2019
1 parent cbef15f commit 77f861e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions types/lib/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2728,6 +2728,15 @@ export abstract class Model<T = any, T2 = any> extends Hooks {
* values gotten from the DB, and apply all custom getters.
*/
public toJSON(): object;

/**
* Helper method to determine if a instance is "soft deleted". This is
* particularly useful if the implementer renamed the deletedAt attribute to
* something different. This method requires paranoid to be enabled.
*
* Throws an error if paranoid is not enabled.
*/
public isSoftDeleted(): boolean;
}

export type ModelType = typeof Model;
Expand Down
3 changes: 3 additions & 0 deletions types/test/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@ User.scope([
'custom2',
{ method: [ 'custom', 32 ] }
])

const instance = new User({ username: 'foo', firstName: 'bar', lastName: 'baz' });
instance.isSoftDeleted()

0 comments on commit 77f861e

Please sign in to comment.