@@ -23,7 +23,7 @@ export abstract class CreateRunnerGroup {
|
||||
* Get's this group's contact from this.address.
|
||||
*/
|
||||
public async getContact(): Promise<GroupContact> {
|
||||
if (this.contact === undefined) {
|
||||
if (this.contact === undefined || this.contact === null) {
|
||||
return null;
|
||||
}
|
||||
if (!isNaN(this.contact)) {
|
||||
|
||||
50
src/models/actions/UpdateRunnerTeam.ts
Normal file
50
src/models/actions/UpdateRunnerTeam.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { IsInt, IsNotEmpty, IsObject } from 'class-validator';
|
||||
import { getConnectionManager } from 'typeorm';
|
||||
import { RunnerOrganisationNotFoundError, RunnerOrganisationWrongTypeError } from '../../errors/RunnerOrganisationErrors';
|
||||
import { RunnerTeamNeedsParentError } from '../../errors/RunnerTeamErrors';
|
||||
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
|
||||
import { RunnerTeam } from '../entities/RunnerTeam';
|
||||
import { CreateRunnerGroup } from './CreateRunnerGroup';
|
||||
|
||||
export class UpdateRunnerTeam extends CreateRunnerGroup {
|
||||
|
||||
/**
|
||||
* The updated team's id.
|
||||
*/
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The team's parent group (organisation).
|
||||
*/
|
||||
@IsObject()
|
||||
@IsNotEmpty()
|
||||
parentGroup: RunnerOrganisation;
|
||||
|
||||
public async getParent(): Promise<RunnerOrganisation> {
|
||||
if (this.parentGroup === undefined) {
|
||||
throw new RunnerTeamNeedsParentError();
|
||||
}
|
||||
if (!isNaN(this.parentGroup.id)) {
|
||||
let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup.id });
|
||||
if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; }
|
||||
return parentGroup;
|
||||
}
|
||||
|
||||
throw new RunnerOrganisationWrongTypeError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a RunnerTeam entity from this.
|
||||
*/
|
||||
public async toRunnerTeam(): Promise<RunnerTeam> {
|
||||
let newRunnerTeam: RunnerTeam = new RunnerTeam();
|
||||
|
||||
newRunnerTeam.id = this.id;
|
||||
newRunnerTeam.name = this.name;
|
||||
newRunnerTeam.parentGroup = await this.getParent();
|
||||
newRunnerTeam.contact = await this.getContact()
|
||||
|
||||
return newRunnerTeam;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user