-
Notifications
You must be signed in to change notification settings - Fork 368
Use cases for intent based CRUD hooks
Raymond Feng edited this page Mar 9, 2015
·
14 revisions
We recently received some feedbacks on the intent-based CRUD hooks.
- https://github.com/strongloop/loopback-datasource-juggler/pull/488
- https://github.com/strongloop/loopback-datasource-juggler/issues/482
There are issues and ideas raised. We would like to fully understand the use cases to decide what's the best way to enhance the hook apis, especially the ctx structure. Community input is critical to make the exercise successful. Please contribute your use cases below.
There are different types of methods that trigger a hook function:
- prototype methods, such as
updateAttributes,save, anddelete. They work on a given model instance. - static methods, such as
create,updateAll, anddeleteAll. They work on the a given model class.
There are a few categories I can see:
- In a
beforehook, perform additional operations. - In a
beforehook, run some validations and fail fast. - In a
beforehook, change/transform the input to the target DB operation. - In a
afterhook, perform additional operations based on the outcome of the CRUD. - In a
afterhook, change/transform the output from the target DB operation so that the callback/promise will receive a modified result.
Use cases from Raymond:
- Calculate a license key for a subscription record before it's save to the DB. The license key is derived from a