loopbackio / loopbackio/loopback-next

@loopback/cli: Controller rest generator with findOne method

Open
#5,531 4 comments 0 reactions 1 assignee View on GitHub

@mrnetforge is already working on this.

Since May 24, 2020.

CLI developer-experience feature help wanted
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.