37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
|
import { getConnectionManager } from 'typeorm';
|
|
import { GroupContactNotFoundError, GroupContactWrongTypeError } from '../../errors/GroupContactErrors';
|
|
import { GroupContact } from '../entities/GroupContact';
|
|
|
|
export abstract class CreateRunnerGroup {
|
|
/**
|
|
* The group's name.
|
|
*/
|
|
@IsNotEmpty()
|
|
@IsString()
|
|
name: string;
|
|
|
|
/**
|
|
* The group's contact.
|
|
* Optional
|
|
*/
|
|
@IsInt()
|
|
@IsOptional()
|
|
contact?: number;
|
|
|
|
/**
|
|
* Deals with the contact for groups this.
|
|
*/
|
|
public async getContact(): Promise<GroupContact> {
|
|
if (this.contact === undefined) {
|
|
return null;
|
|
}
|
|
if (!isNaN(this.contact)) {
|
|
let address = await getConnectionManager().get().getRepository(GroupContact).findOne({ id: this.contact });
|
|
if (!address) { throw new GroupContactNotFoundError; }
|
|
return address;
|
|
}
|
|
|
|
throw new GroupContactWrongTypeError;
|
|
}
|
|
} |