loopbackio / loopbackio/loopback-next
@loopback/cli: Controller rest generator with findOne method
@mrnetforge is already working on this.
Since May 24, 2020.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
## Suggestion
Currently, cli generator controller doesn't provide findOne method inside file. Method findOne exists in repository that is associated with controller, so i think i should be generated. For now i must manually add this method to all my controllers
```ts
@get('/config/findOne', {
responses: {
'200': {
description: 'Config model instance',
content: {
'application/json': {
schema: getModelSchemaRef(Config, { includeRelations: true }),
},
},
},
},
})
async findOne(
@param.filter(Config) filter?: Filter,
): Promise {
return this.configRepository.findOne(filter);
}
```
## Use Cases
`lb4 controller` with REST option should create findOne inside controller (example above)
## Examples
In my scenario i have model that i need to find not by id but based on custom filter. It would be much easier when this method can be created out of the box.
## Acceptance criteria
TBD - will be filled by the team.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.