Using our models
When having to connect requests to data models, the typical approach in Nest.js is building dedicated services, which serve as the “touch point” with each model, and to build controllers, which link the services to the requests reaching the API. Let’s follow the model -> service -> controller
approach in the following steps.
The service
In a typical Nest.js architecture, the application heavy-lifting is done by the services. In order to follow this pattern, create a new EntriesService
, using it to interact with the Entry
entity.
So, let’s create a new file at:
src/entries/entries.service.ts
import
{
Component
}
from
'@nestjs/common'
;
import
{
InjectRepository
}
from
'@nestjs/typeorm'
;
import
{
Repository
}
from
'typeorm'
;
import
{
Entry
}
from
'./entry.entity'
;
@
Injectable
()
export
class
EntriesService
{
constructor
(
// we create a repository for the Entry entity
// and then we inject...