loopback-next
loopback-next copied to clipboard
fix: enable controller update in case of multiple belongsTo relation
While trying to create more than one belongsTo relation, cli asks to replace the controller file. The model and repository files are correctly updated. This PR enables the update of the controller to include new relations.
Checklist
- [x] DCO (Developer Certificate of Origin) signed in all commits
- [x]
npm test
passes on your machine - [x] New tests added or existing tests modified to cover all changes
- [x] Code conforms with the style guide
- [ ] API Documentation in code was updated
- [ ] Documentation in /docs/site was updated
- [x] Affected artifact templates in
packages/cli
were updated - [ ] Affected example projects in
examples/*
were updated
Pull Request Test Coverage Report for Build 7811138626
- 0 of 0 changed or added relevant lines in 0 files are covered.
- No unchanged relevant lines lost coverage.
- Overall first build on fix/multi-belongsTo at 55.371%
Totals | |
---|---|
Change from base Build 7776209974: | 55.4% |
Covered Lines: | 9563 |
Relevant Lines: | 12457 |
💛 - Coveralls
Hi, @samarpanB. Please have a look at the PR whenever you have the chance.
Though I have added the tests and they are passing, the snapshot added is not what the results should look like.
I have tried the changes locally and they work totally fine.
The controller in the snapshot looks like this:
import {
repository,
} from '@loopback/repository';
import {
param,
get,
getModelSchemaRef,
} from '@loopback/rest';
import {
Task,
Employee,
} from '../models';
import {TaskRepository} from '../repositories';
export class TaskEmployeeController {
constructor(
@repository(TaskRepository)
public taskRepository: TaskRepository,
) { }
@get('/tasks/{id}/employee', {
responses: {
'200': {
description: 'Employee belonging to Task',
content: {
'application/json': {
schema: getModelSchemaRef(Employee),
},
},
},
},
})
async getEmployee(
@param.path.number('id') id: typeof Task.prototype.id,
): Promise<Employee> {
return this.taskRepository.assignedTo(id);
}
}
While it should be like the following:
import {
repository,
} from '@loopback/repository';
import {
param,
get,
getModelSchemaRef,
} from '@loopback/rest';
import {
Task,
Employee,
} from '../models';
import {TaskRepository} from '../repositories';
export class TaskEmployeeController {
constructor(
@repository(TaskRepository)
public taskRepository: TaskRepository,
) { }
@get('/tasks/{id}/employee', {
responses: {
'200': {
description: 'Employee belonging to Task',
content: {
'application/json': {
schema: getModelSchemaRef(Employee),
},
},
},
},
})
async getEmployee(
@param.path.number('id') id: typeof Task.prototype.id,
): Promise<Promise<Employee>> {
return [this.taskRepository.assignedTo(id), this.taskRepository.assignedTo(id)];
}
}