Compare commits
No commits in common. "92186a86cccf190ea20fb941be95ecb8c7be111c" and "9b5d16ae92045580a748c820d0af64950cf2fdfd" have entirely different histories.
92186a86cc
...
9b5d16ae92
@ -29,7 +29,7 @@ export class RunnerOrganisationController {
|
|||||||
@OpenAPI({ description: 'Lists all organisations. <br> This includes their address, contact and teams (if existing/associated).' })
|
@OpenAPI({ description: 'Lists all organisations. <br> This includes their address, contact and teams (if existing/associated).' })
|
||||||
async getAll() {
|
async getAll() {
|
||||||
let responseTeams: ResponseRunnerOrganisation[] = new Array<ResponseRunnerOrganisation>();
|
let responseTeams: ResponseRunnerOrganisation[] = new Array<ResponseRunnerOrganisation>();
|
||||||
const runners = await this.runnerOrganisationRepository.find({ relations: ['address', 'contact', 'teams'] });
|
const runners = await this.runnerOrganisationRepository.find({ relations: [/*'address',*/ 'contact', 'teams'] });
|
||||||
runners.forEach(runner => {
|
runners.forEach(runner => {
|
||||||
responseTeams.push(new ResponseRunnerOrganisation(runner));
|
responseTeams.push(new ResponseRunnerOrganisation(runner));
|
||||||
});
|
});
|
||||||
@ -43,7 +43,7 @@ export class RunnerOrganisationController {
|
|||||||
@OnUndefined(RunnerOrganisationNotFoundError)
|
@OnUndefined(RunnerOrganisationNotFoundError)
|
||||||
@OpenAPI({ description: 'Lists all information about the organisation whose id got provided.' })
|
@OpenAPI({ description: 'Lists all information about the organisation whose id got provided.' })
|
||||||
async getOne(@Param('id') id: number) {
|
async getOne(@Param('id') id: number) {
|
||||||
let runnerOrg = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] });
|
let runnerOrg = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: [/*'address',*/ 'contact', 'teams'] });
|
||||||
if (!runnerOrg) { throw new RunnerOrganisationNotFoundError(); }
|
if (!runnerOrg) { throw new RunnerOrganisationNotFoundError(); }
|
||||||
return new ResponseRunnerOrganisation(runnerOrg);
|
return new ResponseRunnerOrganisation(runnerOrg);
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ export class RunnerOrganisationController {
|
|||||||
|
|
||||||
runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation);
|
runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation);
|
||||||
|
|
||||||
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] }));
|
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: [/*'address',*/ 'contact', 'teams'] }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:id')
|
@Put('/:id')
|
||||||
@ -84,7 +84,7 @@ export class RunnerOrganisationController {
|
|||||||
|
|
||||||
await this.runnerOrganisationRepository.save(await updateOrganisation.updateRunnerOrganisation(oldRunnerOrganisation));
|
await this.runnerOrganisationRepository.save(await updateOrganisation.updateRunnerOrganisation(oldRunnerOrganisation));
|
||||||
|
|
||||||
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(id, { relations: ['address', 'contact', 'teams'] }));
|
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(id, { relations: [/*'address',*/ 'contact', 'teams'] }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete('/:id')
|
@Delete('/:id')
|
||||||
@ -98,7 +98,7 @@ export class RunnerOrganisationController {
|
|||||||
async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
|
async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
|
||||||
let organisation = await this.runnerOrganisationRepository.findOne({ id: id });
|
let organisation = await this.runnerOrganisationRepository.findOne({ id: id });
|
||||||
if (!organisation) { return null; }
|
if (!organisation) { return null; }
|
||||||
let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organisation, { relations: ['address', 'contact', 'runners', 'teams'] });
|
let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organisation, { relations: [/*'address',*/ 'contact', 'runners', 'teams'] });
|
||||||
|
|
||||||
if (!force) {
|
if (!force) {
|
||||||
if (runnerOrganisation.teams.length != 0) {
|
if (runnerOrganisation.teams.length != 0) {
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||||
import { config } from '../../config';
|
import { config } from '../../config';
|
||||||
import { IAddressUser } from './IAddressUser';
|
import { Participant } from "./Participant";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the Address entity.
|
* Defines the Address entity.
|
||||||
@ -78,6 +78,13 @@ export class Address {
|
|||||||
/**
|
/**
|
||||||
* Used to link the address to participants.
|
* Used to link the address to participants.
|
||||||
*/
|
*/
|
||||||
@OneToMany(() => IAddressUser, addressUser => addressUser.address, { nullable: true })
|
@OneToMany(() => Participant, participant => participant.address, { nullable: true })
|
||||||
addressUsers: IAddressUser[];
|
participants: Participant[];
|
||||||
|
|
||||||
|
//TODO: #68
|
||||||
|
// /**
|
||||||
|
// * Used to link the address to runner groups.
|
||||||
|
// */
|
||||||
|
// @OneToMany(() => RunnerOrganisation, group => group.address, { nullable: true })
|
||||||
|
// groups: RunnerOrganisation[];
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import {
|
|||||||
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||||
import { config } from '../../config';
|
import { config } from '../../config';
|
||||||
import { Address } from "./Address";
|
import { Address } from "./Address";
|
||||||
import { IAddressUser } from './IAddressUser';
|
|
||||||
import { RunnerGroup } from "./RunnerGroup";
|
import { RunnerGroup } from "./RunnerGroup";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,7 +17,7 @@ import { RunnerGroup } from "./RunnerGroup";
|
|||||||
* Mainly it's own class to reduce duplicate code and enable contact's to be associated with multiple groups.
|
* Mainly it's own class to reduce duplicate code and enable contact's to be associated with multiple groups.
|
||||||
*/
|
*/
|
||||||
@Entity()
|
@Entity()
|
||||||
export class GroupContact implements IAddressUser {
|
export class GroupContact {
|
||||||
/**
|
/**
|
||||||
* Autogenerated unique id (primary key).
|
* Autogenerated unique id (primary key).
|
||||||
*/
|
*/
|
||||||
@ -55,7 +54,7 @@ export class GroupContact implements IAddressUser {
|
|||||||
* This is a address object to prevent any formatting differences.
|
* This is a address object to prevent any formatting differences.
|
||||||
*/
|
*/
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ManyToOne(() => Address, address => address.addressUsers, { nullable: true })
|
@ManyToOne(() => Address, address => address.participants, { nullable: true })
|
||||||
address?: Address;
|
address?: Address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
import { Entity, ManyToOne, PrimaryColumn } from 'typeorm';
|
|
||||||
import { Address } from './Address';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface(tm) all entities using addresses have to implement.
|
|
||||||
* This is a abstract class, because apparently typeorm can't really work with interfaces :/
|
|
||||||
*/
|
|
||||||
@Entity()
|
|
||||||
export abstract class IAddressUser {
|
|
||||||
@PrimaryColumn()
|
|
||||||
id: number;
|
|
||||||
|
|
||||||
@ManyToOne(() => Address, address => address.addressUsers, { nullable: true })
|
|
||||||
address?: Address
|
|
||||||
}
|
|
@ -10,7 +10,6 @@ import {
|
|||||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
|
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
|
||||||
import { config } from '../../config';
|
import { config } from '../../config';
|
||||||
import { Address } from "./Address";
|
import { Address } from "./Address";
|
||||||
import { IAddressUser } from './IAddressUser';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the Participant entity.
|
* Defines the Participant entity.
|
||||||
@ -18,7 +17,7 @@ import { IAddressUser } from './IAddressUser';
|
|||||||
*/
|
*/
|
||||||
@Entity()
|
@Entity()
|
||||||
@TableInheritance({ column: { name: "type", type: "varchar" } })
|
@TableInheritance({ column: { name: "type", type: "varchar" } })
|
||||||
export abstract class Participant implements IAddressUser {
|
export abstract class Participant {
|
||||||
/**
|
/**
|
||||||
* Autogenerated unique id (primary key).
|
* Autogenerated unique id (primary key).
|
||||||
*/
|
*/
|
||||||
@ -54,7 +53,7 @@ export abstract class Participant implements IAddressUser {
|
|||||||
* The participant's address.
|
* The participant's address.
|
||||||
* This is a address object to prevent any formatting differences.
|
* This is a address object to prevent any formatting differences.
|
||||||
*/
|
*/
|
||||||
@ManyToOne(() => Address, address => address.addressUsers, { nullable: true })
|
@ManyToOne(() => Address, address => address.participants, { nullable: true })
|
||||||
address?: Address;
|
address?: Address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import { IsInt, IsOptional } from "class-validator";
|
import { IsInt } from "class-validator";
|
||||||
import { ChildEntity, ManyToOne, OneToMany } from "typeorm";
|
import { ChildEntity, OneToMany } from "typeorm";
|
||||||
import { Address } from './Address';
|
|
||||||
import { IAddressUser } from './IAddressUser';
|
|
||||||
import { Runner } from './Runner';
|
import { Runner } from './Runner';
|
||||||
import { RunnerGroup } from "./RunnerGroup";
|
import { RunnerGroup } from "./RunnerGroup";
|
||||||
import { RunnerTeam } from "./RunnerTeam";
|
import { RunnerTeam } from "./RunnerTeam";
|
||||||
@ -11,14 +9,14 @@ import { RunnerTeam } from "./RunnerTeam";
|
|||||||
* This usually is a school, club or company.
|
* This usually is a school, club or company.
|
||||||
*/
|
*/
|
||||||
@ChildEntity()
|
@ChildEntity()
|
||||||
export class RunnerOrganisation extends RunnerGroup implements IAddressUser {
|
export class RunnerOrganisation extends RunnerGroup {
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* The organisations's address.
|
// * The organisations's address.
|
||||||
*/
|
// */
|
||||||
@IsOptional()
|
// @IsOptional()
|
||||||
@ManyToOne(() => Address, address => address.addressUsers, { nullable: true })
|
// @ManyToOne(() => Address, address => address.groups, { nullable: true })
|
||||||
address?: Address;
|
// address?: Address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The organisation's teams.
|
* The organisation's teams.
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
IsArray,
|
IsArray,
|
||||||
|
IsNotEmpty,
|
||||||
IsObject,
|
IsObject
|
||||||
IsOptional
|
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
import { Address } from '../entities/Address';
|
import { Address } from '../entities/Address';
|
||||||
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
|
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
|
||||||
@ -18,7 +17,7 @@ export class ResponseRunnerOrganisation extends ResponseRunnerGroup {
|
|||||||
* The runnerOrganisation's address.
|
* The runnerOrganisation's address.
|
||||||
*/
|
*/
|
||||||
@IsObject()
|
@IsObject()
|
||||||
@IsOptional()
|
@IsNotEmpty()
|
||||||
address?: Address;
|
address?: Address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +32,7 @@ export class ResponseRunnerOrganisation extends ResponseRunnerGroup {
|
|||||||
*/
|
*/
|
||||||
public constructor(org: RunnerOrganisation) {
|
public constructor(org: RunnerOrganisation) {
|
||||||
super(org);
|
super(org);
|
||||||
this.address = org.address;
|
// this.address = org.address;
|
||||||
this.teams = org.teams;
|
this.teams = org.teams;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ describe('adding + getting from all orgs', () => {
|
|||||||
expect(added_org).toEqual({
|
expect(added_org).toEqual({
|
||||||
"name": "test123",
|
"name": "test123",
|
||||||
"contact": null,
|
"contact": null,
|
||||||
"address": null,
|
// "address": null,
|
||||||
"teams": []
|
"teams": []
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -83,7 +83,7 @@ describe('adding + getting explicitly', () => {
|
|||||||
expect(added_org2).toEqual({
|
expect(added_org2).toEqual({
|
||||||
"name": "test123",
|
"name": "test123",
|
||||||
"contact": null,
|
"contact": null,
|
||||||
"address": null,
|
// "address": null,
|
||||||
"teams": []
|
"teams": []
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -44,7 +44,7 @@ describe('adding + deletion (successfull)', () => {
|
|||||||
expect(added_org2).toEqual({
|
expect(added_org2).toEqual({
|
||||||
"name": "test123",
|
"name": "test123",
|
||||||
"contact": null,
|
"contact": null,
|
||||||
"address": null,
|
// "address": null,
|
||||||
"teams": []
|
"teams": []
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -121,7 +121,7 @@ describe('adding + deletion with teams still existing (with force)', () => {
|
|||||||
expect(added_org2).toEqual({
|
expect(added_org2).toEqual({
|
||||||
"name": "test123",
|
"name": "test123",
|
||||||
"contact": null,
|
"contact": null,
|
||||||
"address": null
|
// "address": null
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('check if org really was deleted', async () => {
|
it('check if org really was deleted', async () => {
|
||||||
|
@ -32,7 +32,7 @@ describe('adding + updating name', () => {
|
|||||||
"id": added_org_id,
|
"id": added_org_id,
|
||||||
"name": "testlelele",
|
"name": "testlelele",
|
||||||
"contact": null,
|
"contact": null,
|
||||||
"address": null,
|
// "address": null,
|
||||||
}, axios_config);
|
}, axios_config);
|
||||||
expect(res2.status).toEqual(200);
|
expect(res2.status).toEqual(200);
|
||||||
expect(res2.headers['content-type']).toContain("application/json")
|
expect(res2.headers['content-type']).toContain("application/json")
|
||||||
@ -42,7 +42,7 @@ describe('adding + updating name', () => {
|
|||||||
expect(added_org2).toEqual({
|
expect(added_org2).toEqual({
|
||||||
"name": "testlelele",
|
"name": "testlelele",
|
||||||
"contact": null,
|
"contact": null,
|
||||||
"address": null,
|
// "address": null,
|
||||||
"teams": []
|
"teams": []
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -65,7 +65,7 @@ describe('adding + try updating id (should return 406)', () => {
|
|||||||
"id": added_org_id + 1,
|
"id": added_org_id + 1,
|
||||||
"name": "testlelele",
|
"name": "testlelele",
|
||||||
"contact": null,
|
"contact": null,
|
||||||
"address": null,
|
// "address": null,
|
||||||
}, axios_config);
|
}, axios_config);
|
||||||
expect(res2.status).toEqual(406);
|
expect(res2.status).toEqual(406);
|
||||||
expect(res2.headers['content-type']).toContain("application/json")
|
expect(res2.headers['content-type']).toContain("application/json")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user