From 7fb16fc93d5796575a834761397cfe1ab9d68eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Adem=20I=C5=9EIKLI?= Date: Mon, 8 Apr 2024 22:36:37 +0200 Subject: [PATCH] Added index.ts documentation for hooks --- docs/learn/hooks-and-events.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/learn/hooks-and-events.md b/docs/learn/hooks-and-events.md index 8181af4..e72f16f 100644 --- a/docs/learn/hooks-and-events.md +++ b/docs/learn/hooks-and-events.md @@ -128,6 +128,26 @@ Let's check out the following example; - `All`: The action of data fetching all. - `Show`: The action of fetching one item. +## `index.ts` file + +As an alternative, you can use an `index.ts` file for each model that contains all of your hooks functions inside. + +::: code-group + +```ts [app/v1/Hooks/User/index.ts] +import { IContext } from "axe-api"; + +export const onBeforeInsert = async (context: IContext) => { + // add your custom logic in here +}; + +export const onAfterInsert = async (context: IContext) => { + // add your custom logic in here +}; +``` + +::: + ## HTTP Request-Response Cycle Hook and event functions would be executed after the middlewares and the before serializer.