28 lines
733 B
TypeScript
28 lines
733 B
TypeScript
import { IsOptional, IsString } from 'class-validator';
|
|
import { GroupNameNeededError } from '../../errors/UserGroupErrors';
|
|
import { UserGroup } from '../entities/UserGroup';
|
|
|
|
export class CreateUserGroup {
|
|
@IsOptional()
|
|
@IsString()
|
|
name: string;
|
|
@IsOptional()
|
|
@IsString()
|
|
description?: string;
|
|
|
|
public async toUserGroup(): Promise<UserGroup> {
|
|
let newUserGroup: UserGroup = new UserGroup();
|
|
|
|
if (this.name === undefined) {
|
|
throw new GroupNameNeededError();
|
|
}
|
|
|
|
newUserGroup.name = this.name
|
|
if (this.description) {
|
|
newUserGroup.description = this.description
|
|
}
|
|
|
|
console.log(newUserGroup)
|
|
return newUserGroup;
|
|
}
|
|
} |