Services
Logic for API endpoints.
This guide is based of NestJS documentation.
Services are used to encapsulate the business logic of your application. They are responsible for handling data and implementing the application's logic. Services are used by controllers to handle incoming requests.
Creating a service
To create a new service, create a file in the apps/backend/src/plugins/{your_plugin_code}/services
directory. The service should be decorated with the @Injectable()
decorator.
The @Injectable()
decorator marks the class as a provider. This decorator is required for all providers in NestJS.
Import into module
To use the service, import it into the module where it will be used. Go to the module root
of your plugin. That's should be apps/backend/src/plugins/{your_plugin_code}/{your_plugin_code}.module.ts
. Import the service and add it to the providers
array.
Usage in controller
To use the service in a controller, import it and inject it into the controller's constructor.