Fixed some stuff not getting checked against null

ref #39 gosh i sometimes hate js types
This commit is contained in:
Nicolai Ort 2020-12-20 18:18:32 +01:00
parent fbe2b358bd
commit 7a4238f1f7
10 changed files with 15 additions and 19 deletions

View File

@ -56,7 +56,7 @@ export class CreateGroupContact {
* Get's this participant's address from this.address.
*/
public async getAddress(): Promise<Address> {
if (this.address === undefined) {
if (this.address === undefined || this.address === null) {
return null;
}
if (!isNaN(this.address)) {

View File

@ -58,7 +58,7 @@ export abstract class CreateParticipant {
* Get's this participant's address from this.address.
*/
public async getAddress(): Promise<Address> {
if (this.address === undefined) {
if (this.address === undefined || this.address === null) {
return null;
}
if (!isNaN(this.address)) {

View File

@ -36,7 +36,7 @@ export class CreateRunner extends CreateParticipant {
* Manages all the different ways a group can be provided.
*/
public async getGroup(): Promise<RunnerGroup> {
if (this.group === undefined) {
if (this.group === undefined || this.group === null) {
throw new RunnerTeamNeedsParentError();
}
if (!isNaN(this.group)) {

View File

@ -19,7 +19,7 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
* Get's this org's address from this.address.
*/
public async getAddress(): Promise<Address> {
if (this.address === undefined) {
if (this.address === undefined || this.address === null) {
return null;
}
if (!isNaN(this.address)) {

View File

@ -16,7 +16,7 @@ export class CreateRunnerTeam extends CreateRunnerGroup {
parentGroup: number;
public async getParent(): Promise<RunnerOrganisation> {
if (this.parentGroup === undefined) {
if (this.parentGroup === undefined || this.parentGroup === null) {
throw new RunnerTeamNeedsParentError();
}
if (!isNaN(this.parentGroup)) {

View File

@ -49,7 +49,7 @@ export class UpdatePermission {
* Manages all the different ways a group can be provided.
*/
public async getPrincipal(): Promise<Principal> {
if (this.principal === undefined) {
if (this.principal === undefined || this.principal === null) {
throw new PermissionNeedsPrincipalError();
}
if (!isNaN(this.principal.id)) {

View File

@ -40,7 +40,7 @@ export class UpdateRunner extends CreateParticipant {
* Manages all the different ways a group can be provided.
*/
public async getGroup(): Promise<RunnerGroup> {
if (this.group === undefined) {
if (this.group === undefined || this.group === null) {
throw new RunnerTeamNeedsParentError();
}
if (!isNaN(this.group.id)) {

View File

@ -1,6 +1,6 @@
import { IsInt, IsOptional } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/AddressErrors';
import { AddressNotFoundError } from '../../errors/AddressErrors';
import { Address } from '../entities/Address';
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
import { CreateRunnerGroup } from './CreateRunnerGroup';
@ -20,22 +20,18 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup {
*/
@IsInt()
@IsOptional()
address?: number;
address?: Address;
/**
* Get's this org's address from this.address.
*/
public async getAddress(): Promise<Address> {
if (this.address === undefined) {
if (this.address === undefined || this.address === null) {
return null;
}
if (!isNaN(this.address)) {
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
if (!address) { throw new AddressNotFoundError; }
return address;
}
throw new AddressWrongTypeError;
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address.id });
if (!address) { throw new AddressNotFoundError; }
return address;
}
/**

View File

@ -22,7 +22,7 @@ export class UpdateRunnerTeam extends CreateRunnerGroup {
parentGroup: RunnerOrganisation;
public async getParent(): Promise<RunnerOrganisation> {
if (this.parentGroup === undefined) {
if (this.parentGroup === undefined || this.parentGroup === null) {
throw new RunnerTeamNeedsParentError();
}
if (!isNaN(this.parentGroup.id)) {

View File

@ -88,7 +88,7 @@ export class UpdateUser {
public async updateUser(user: User): Promise<User> {
user.email = this.email;
user.username = this.username;
if (user.email === undefined && user.username === undefined) {
if ((user.email === undefined || user.email === null) && (user.username === undefined || user.username === null)) {
throw new UsernameOrEmailNeededError();
}
if (this.password) {