Merge branch 'dev' into feature/123-mail_documentation
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
commit
80e606aa96
@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file. Dates are d
|
||||
|
||||
#### [v0.3.1](https://git.odit.services/lfk/backend/compare/v0.3.0...v0.3.1)
|
||||
|
||||
- Merge pull request 'new advanced endpoints feature/125-team_runner' (#126) from feature/125-team_runner into dev [`870fd47`](https://git.odit.services/lfk/backend/commit/870fd47c83389345d7b24a15df6a4e61e930d140)
|
||||
- Added get runners by team test [`69417e9`](https://git.odit.services/lfk/backend/commit/69417e93c081422561db1e211b12f32e539010ce)
|
||||
- 🧾New changelog file version [CI SKIP] [skip ci] [`71898d5`](https://git.odit.services/lfk/backend/commit/71898d576c2620d2f2e2b4336e62f1d04a443201)
|
||||
- Created the organizations/runners endpoint [`570c34b`](https://git.odit.services/lfk/backend/commit/570c34bed04e359f389a8f427486bf92891f1dcb)
|
||||
- Created the runnerTeam/runners endpoint [`7be2971`](https://git.odit.services/lfk/backend/commit/7be2971a9e02bf0e784f7fe5cdd82afbbbf7f854)
|
||||
- 🧾New changelog file version [CI SKIP] [skip ci] [`aedfcfc`](https://git.odit.services/lfk/backend/commit/aedfcfcc8359afd7dba4fa5e515e8e77fbb3fc6e)
|
||||
- Added get runners by org test [`f71a22f`](https://git.odit.services/lfk/backend/commit/f71a22f4dd9bf14d39ced91908f6f6a5d8395e56)
|
||||
- 🚀Bumped version to v0.3.1 [`db08760`](https://git.odit.services/lfk/backend/commit/db0876015bf0599dabb21357f172735888c79aa8)
|
||||
|
||||
#### [v0.3.0](https://git.odit.services/lfk/backend/compare/v0.2.1...v0.3.0)
|
||||
|
@ -4,8 +4,10 @@ import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { RunnerOrganizationHasRunnersError, RunnerOrganizationHasTeamsError, RunnerOrganizationIdsNotMatchingError, RunnerOrganizationNotFoundError } from '../errors/RunnerOrganizationErrors';
|
||||
import { CreateRunnerOrganization } from '../models/actions/create/CreateRunnerOrganization';
|
||||
import { UpdateRunnerOrganization } from '../models/actions/update/UpdateRunnerOrganization';
|
||||
import { Runner } from '../models/entities/Runner';
|
||||
import { RunnerOrganization } from '../models/entities/RunnerOrganization';
|
||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
||||
import { ResponseRunner } from '../models/responses/ResponseRunner';
|
||||
import { ResponseRunnerOrganization } from '../models/responses/ResponseRunnerOrganization';
|
||||
import { RunnerController } from './RunnerController';
|
||||
import { RunnerTeamController } from './RunnerTeamController';
|
||||
@ -48,6 +50,22 @@ export class RunnerOrganizationController {
|
||||
return new ResponseRunnerOrganization(runnerOrg);
|
||||
}
|
||||
|
||||
@Get('/:id/runners')
|
||||
@Authorized(["RUNNER:GET", "SCAN:GET"])
|
||||
@ResponseSchema(ResponseRunner, { isArray: true })
|
||||
@ResponseSchema(RunnerOrganizationNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: 'Lists all runners from this org and it\'s teams (if you don\'t provide the ?onlyDirect=true param). <br> This includes the runner\'s group and distance ran.' })
|
||||
async getRunners(@Param('id') id: number, @QueryParam('onlyDirect') onlyDirect: boolean) {
|
||||
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
||||
let runners: Runner[];
|
||||
if (!onlyDirect) { runners = (await this.runnerOrganizationRepository.findOne({ id: id }, { relations: ['runners', 'runners.group', 'runners.scans', 'runners.scans.track', 'teams', 'teams.runners', 'teams.runners.group', 'teams.runners.scans', 'teams.runners.scans.track'] })).allRunners; }
|
||||
else { runners = (await this.runnerOrganizationRepository.findOne({ id: id }, { relations: ['runners', 'runners.group', 'runners.scans', 'runners.scans.track'] })).runners; }
|
||||
runners.forEach(runner => {
|
||||
responseRunners.push(new ResponseRunner(runner));
|
||||
});
|
||||
return responseRunners;
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Authorized("ORGANIZATION:CREATE")
|
||||
@ResponseSchema(ResponseRunnerOrganization)
|
||||
|
@ -6,6 +6,7 @@ import { CreateRunnerTeam } from '../models/actions/create/CreateRunnerTeam';
|
||||
import { UpdateRunnerTeam } from '../models/actions/update/UpdateRunnerTeam';
|
||||
import { RunnerTeam } from '../models/entities/RunnerTeam';
|
||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
||||
import { ResponseRunner } from '../models/responses/ResponseRunner';
|
||||
import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam';
|
||||
import { RunnerController } from './RunnerController';
|
||||
|
||||
@ -47,6 +48,20 @@ export class RunnerTeamController {
|
||||
return new ResponseRunnerTeam(runnerTeam);
|
||||
}
|
||||
|
||||
@Get('/:id/runners')
|
||||
@Authorized(["RUNNER:GET", "SCAN:GET"])
|
||||
@ResponseSchema(ResponseRunner, { isArray: true })
|
||||
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: 'Lists all runners from this team. <br> This includes the runner\'s group and distance ran.' })
|
||||
async getRunners(@Param('id') id: number) {
|
||||
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
||||
const runners = (await this.runnerTeamRepository.findOne({ id: id }, { relations: ['runners', 'runners.group', 'runners.scans', 'runners.scans.track'] })).runners;
|
||||
runners.forEach(runner => {
|
||||
responseRunners.push(new ResponseRunner(runner));
|
||||
});
|
||||
return responseRunners;
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Authorized("TEAM:CREATE")
|
||||
@ResponseSchema(ResponseRunnerTeam)
|
||||
|
@ -33,36 +33,106 @@ describe('GET /api/runners after adding', () => {
|
||||
let added_org_id;
|
||||
let added_runner;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organizations', {
|
||||
const res = await axios.post(base + '/api/organizations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
let added_org = res1.data
|
||||
let added_org = res.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
const res = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org_id
|
||||
}, axios_config);
|
||||
added_runner = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
added_runner = res.data;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('explicit get should return 200', async () => {
|
||||
const res3 = await axios.get(base + '/api/runners/' + added_runner.id, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
let gotten_runner = res3.data
|
||||
const res = await axios.get(base + '/api/runners/' + added_runner.id, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
let gotten_runner = res.data
|
||||
expect(gotten_runner).toEqual(added_runner);
|
||||
});
|
||||
it('get from all runners should return 200', async () => {
|
||||
const res4 = await axios.get(base + '/api/runners/', axios_config);
|
||||
expect(res4.status).toEqual(200);
|
||||
expect(res4.headers['content-type']).toContain("application/json")
|
||||
let gotten_runners = res4.data
|
||||
const res = await axios.get(base + '/api/runners/', axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
let gotten_runners = res.data
|
||||
expect(gotten_runners).toContainEqual(added_runner);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('GET /api/organizations/:id/runners after adding', () => {
|
||||
let added_org_id;
|
||||
let added_runner;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/organizations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
let added_org = res.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org_id
|
||||
}, axios_config);
|
||||
added_runner = res.data;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('check if scans was added via the orgs/runners endpoint.', async () => {
|
||||
const res = await axios.get(base + '/api/organizations/' + added_org_id + "/runners", axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
expect(res.data).toContainEqual(added_runner);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('GET /api/teams/:id/runners after adding', () => {
|
||||
let added_org_id;
|
||||
let added_team;
|
||||
let added_runner;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/organizations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
let added_org = res.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a parent org should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/teams', {
|
||||
"name": "test_team",
|
||||
"parentGroup": added_org_id
|
||||
}, axios_config);
|
||||
added_team = res.data;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_team.id
|
||||
}, axios_config);
|
||||
added_runner = res.data;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('check if scans was added via the orgs/runners endpoint.', async () => {
|
||||
const res = await axios.get(base + '/api/teams/' + added_team.id + "/runners", axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
expect(res.data).toContainEqual(added_runner);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user