Cleanup: Renamed the creation folder to the more fitting "actions"
ref #11 #13
This commit is contained in:
37
src/models/actions/CreateRunnerGroup.ts
Normal file
37
src/models/actions/CreateRunnerGroup.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user