Refactoring: switched update org address from objects to ids

ref #90
This commit is contained in:
Nicolai Ort 2021-01-15 18:30:20 +01:00
parent e96637219f
commit 97c01ce81a
1 changed files with 4 additions and 8 deletions

View File

@ -18,21 +18,17 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup {
id: number;
/**
* The updated organisation's address.
* Just has to contain the address's id - everything else won't be checked or changed.
* Optional.
* The updated organisation's address's id.
*/
@IsInt()
@IsOptional()
address?: Address;
address?: number;
/**
* Loads the organisation's address based on it's id.
*/
public async getAddress(): Promise<Address> {
if (this.address === undefined || this.address === null) {
return null;
}
if (!this.address) { return null; }
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address.id });
if (!address) { throw new AddressNotFoundError; }
return address;
@ -45,7 +41,7 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup {
organisation.name = this.name;
organisation.contact = await this.getContact();
// organisation.address = await this.getAddress();
organisation.address = await this.getAddress();
return organisation;
}