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

View File

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