Merge pull request 'Runner scans endpoint feature/113-runner_scans' (#116) from feature/113-runner_scans into dev
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #116
This commit is contained in:
commit
36d01a0a89
@ -8,6 +8,8 @@ import { UpdateRunner } from '../models/actions/update/UpdateRunner';
|
|||||||
import { Runner } from '../models/entities/Runner';
|
import { Runner } from '../models/entities/Runner';
|
||||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
||||||
import { ResponseRunner } from '../models/responses/ResponseRunner';
|
import { ResponseRunner } from '../models/responses/ResponseRunner';
|
||||||
|
import { ResponseScan } from '../models/responses/ResponseScan';
|
||||||
|
import { ResponseTrackScan } from '../models/responses/ResponseTrackScan';
|
||||||
import { DonationController } from './DonationController';
|
import { DonationController } from './DonationController';
|
||||||
import { RunnerCardController } from './RunnerCardController';
|
import { RunnerCardController } from './RunnerCardController';
|
||||||
import { ScanController } from './ScanController';
|
import { ScanController } from './ScanController';
|
||||||
@ -49,6 +51,31 @@ export class RunnerController {
|
|||||||
return new ResponseRunner(runner);
|
return new ResponseRunner(runner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('/:id/scans')
|
||||||
|
@Authorized(["RUNNER:GET", "SCAN:GET"])
|
||||||
|
@ResponseSchema(ResponseScan, { isArray: true })
|
||||||
|
@ResponseSchema(ResponseTrackScan, { isArray: true })
|
||||||
|
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||||
|
@OpenAPI({ description: 'Lists all scans of the runner whose id got provided. <br> If you only want the valid scans just add the ?onlyValid=true query param.' })
|
||||||
|
async getScans(@Param('id') id: number, onlyValid?: boolean) {
|
||||||
|
let responseScans: ResponseScan[] = new Array<ResponseScan>();
|
||||||
|
let runner = await this.runnerRepository.findOne({ id: id }, { relations: ['scans', 'scans.track', 'scans.station', 'scans.runner'] })
|
||||||
|
if (!runner) { throw new RunnerNotFoundError(); }
|
||||||
|
|
||||||
|
if (!onlyValid) {
|
||||||
|
for (let scan of runner.scans) {
|
||||||
|
responseScans.push(scan.toResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (let scan of runner.validScans) {
|
||||||
|
responseScans.push(scan.toResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseScans;
|
||||||
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@Authorized("RUNNER:CREATE")
|
@Authorized("RUNNER:CREATE")
|
||||||
@ResponseSchema(ResponseRunner)
|
@ResponseSchema(ResponseRunner)
|
||||||
|
@ -61,9 +61,17 @@ describe('adding + getting scans', () => {
|
|||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
expect(res.headers['content-type']).toContain("application/json")
|
expect(res.headers['content-type']).toContain("application/json")
|
||||||
});
|
});
|
||||||
it('check if scans was added (no parameter validation)', async () => {
|
it('check if scans was added directly', async () => {
|
||||||
const res = await axios.get(base + '/api/scans/' + added_scan.id, axios_config);
|
const res = await axios.get(base + '/api/scans/' + added_scan.id, axios_config);
|
||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
expect(res.headers['content-type']).toContain("application/json");
|
expect(res.headers['content-type']).toContain("application/json");
|
||||||
|
expect(res.data).toEqual(added_scan);
|
||||||
|
});
|
||||||
|
it('check if scans was added via the runner/scans endpoint.', async () => {
|
||||||
|
const res = await axios.get(base + '/api/runners/' + added_runner.id + "/scans", axios_config);
|
||||||
|
expect(res.status).toEqual(200);
|
||||||
|
expect(res.headers['content-type']).toContain("application/json");
|
||||||
|
added_scan.runner.distance = 0;
|
||||||
|
expect(res.data).toContainEqual(added_scan);
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user