Reputation: 33
I'm working with Loopback 4 and I've an abstract model that has some logic methods (that i think can be placed inside that model, like getters, setters and so on) and some of them needs to do some queries to the DB.
I can inject those repositories inside controllers or instantiable models, but how can I access those repositories from inside an abstract model? I can't inject it on the constructor because it'll never be instantiated.
Is it OK to create a "controller" only for this purpose, without exposing API?
Thank you!
EDIT: It seems that injecting the controller inside the model does not work either, it crash when running npm start:
/node_modules/reflect-metadata/Reflect.js:354 throw new TypeError();
TypeError: at Object.getMetadata (/node_modules/reflect-metadata/Reflect.js:354:23)
at NamespacedReflect.getMetadata (/node_modules/@loopback/metadata/src/reflect.ts:49:20)
at Function.getClassMetadata (/node_modules/@loopback/metadata/src/inspector.ts:63:19)
at getJsonSchema (/node_modules/@loopback/repository-json-schema/src/build-schema.ts:89:36)
at Object.getJsonSchemaRef (/node_modules/@loopback/repository-json-schema/src/build-schema.ts:140:33)
at Object.getModelSchemaRef (/node_modules/@loopback/openapi-v3/src/controller-spec.ts:495:22)
at Object.<anonymous> (/src/controllers/api-credential.controller.ts:38:40)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/src/controllers/index.ts:1:1)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
Upvotes: 0
Views: 567
Reputation: 11
There are caches which need to clean up before starting the application.
The project needs to be clean and re-install packages:
npm run clean
npm install
Upvotes: 1