Skip to content

feature(hooks): add decorators for declaring hooks #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 17, 2017

Conversation

natesilva
Copy link
Contributor

@natesilva natesilva commented Aug 17, 2017

I had to re-do the pull request after I botched the original branch. The only change is that this centralizes the hook implementation logic into the hooks services file.

Fixes #88, replaces #97.

@codecov-io
Copy link

codecov-io commented Aug 17, 2017

Codecov Report

Merging #101 into master will increase coverage by 0.64%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #101      +/-   ##
=========================================
+ Coverage   95.66%   96.3%   +0.64%     
=========================================
  Files          66      99      +33     
  Lines         761     893     +132     
  Branches      107     114       +7     
=========================================
+ Hits          728     860     +132     
  Misses         11      11              
  Partials       22      22
Impacted Files Coverage Δ
lib/annotations/hooks/AfterCreate.ts 100% <100%> (ø)
...notations/hooks/BeforeFindAfterExpandIncludeAll.ts 100% <100%> (ø)
lib/annotations/hooks/BeforeDestroy.ts 100% <100%> (ø)
lib/annotations/hooks/AfterRestore.ts 100% <100%> (ø)
lib/annotations/hooks/AfterBulkUpdate.ts 100% <100%> (ø)
lib/annotations/hooks/AfterDestroy.ts 100% <100%> (ø)
lib/annotations/hooks/BeforeBulkDelete.ts 100% <100%> (ø)
lib/annotations/hooks/AfterBulkRestore.ts 100% <100%> (ø)
lib/annotations/hooks/AfterBulkDelete.ts 100% <100%> (ø)
lib/annotations/hooks/BeforeCount.ts 100% <100%> (ø)
... and 57 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1cfa77...2fa0702. Read the comment docs.

@RobinBuschmann RobinBuschmann merged commit 93f5c24 into sequelize:master Aug 17, 2017
@natesilva
Copy link
Contributor Author

Thank you!

@natesilva natesilva deleted the feature/hooks branch August 17, 2017 17:21
@RobinBuschmann
Copy link
Member

Thank you for implementing this. It's a great feature!

@RobinBuschmann
Copy link
Member

RobinBuschmann commented Aug 26, 2017

I've made a beta release, in which this feature is included now :)

npm install [email protected]

@thormengkheang
Copy link

@RobinBuschmann can I use an async function like this?

  @BeforeUpdate
  @BeforeCreate
  static async hashPassword(instance: User) {
    // this will be called when an instance is created or updated
    instance.password = await bcrypt.hash(instance.password, 10);
  }

@natesilva
Copy link
Contributor Author

@mengkheang Yes. A hook function may return a Promise, so async functions are fine. http://docs.sequelizejs.com/manual/tutorial/hooks.html#declaring-hooks

@thormengkheang
Copy link

@natesilva thank for the explaining :)

@RobinBuschmann
Copy link
Member

[email protected] is released now 🎉

@natesilva
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants