Skip to content
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

How to install in Directus CMS #13

Open
danieljwestman opened this issue Oct 11, 2020 · 2 comments
Open

How to install in Directus CMS #13

danieljwestman opened this issue Oct 11, 2020 · 2 comments

Comments

@danieljwestman
Copy link

I'm trying to install and use this hooks on a Directus (v9 - the node version) project.
Can't get it to load properly. I'm following the steps and import knex-hooks in the database file. When running it throws some errors:

npm run dev

[ERROR] 15:07:56 ⨯ Unable to compile TypeScript:

src/database/index.ts:53:10 - error TS2339: Property 'addHook' does not exist on type 'Knex<any, unknown[]>'.

53 database.addHook('before', '*', '*', (when, method, table, params) => {
            ~~~~~~~
src/database/index.ts:53:39 - error TS7006: Parameter 'when' implicitly has an 'any' type.

53 database.addHook('before', '*', '*', (when, method, table, params) => {
                                         ~~~~
src/database/index.ts:53:45 - error TS7006: Parameter 'method' implicitly has an 'any' type.

53 database.addHook('before', '*', '*', (when, method, table, params) => {
                                               ~~~~~~
src/database/index.ts:53:53 - error TS7006: Parameter 'table' implicitly has an 'any' type.

53 database.addHook('before', '*', '*', (when, method, table, params) => {
                                                       ~~~~~
src/database/index.ts:53:60 - error TS7006: Parameter 'params' implicitly has an 'any' type.

53 database.addHook('before', '*', '*', (when, method, table, params) => {

I guess Directus can't load the module. All the other node_modules have a different structure.

Anyone got this to work, in any project type?

@alekbarszczewski
Copy link
Owner

Hey, knex-hooks is missing typescript declarations and this is why TS can't compile your code because it does not know that knex is pacthed and have new method "addHook".

For now you have to manually declare knex method addHook(...) in your code.

@danieljwestman
Copy link
Author

danieljwestman commented Oct 27, 2020

Hi @alekbarszczewski

Thanks for getting back to me in this issue. Sorry for my late response...

I'm not sure I understand. Could you please give me some more simple info/guides on how to setup these hooks (and helpers) in a Node (Express) project like Directus v9?

Big thanks!

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

No branches or pull requests

2 participants