parent
a42595bd15
commit
109e145a19
@ -1,28 +1,30 @@
|
|||||||
import { IsOptional, IsString } from 'class-validator';
|
import { IsOptional, IsString } from 'class-validator';
|
||||||
import { GroupNameNeededError } from '../../errors/UserGroupErrors';
|
|
||||||
import { UserGroup } from '../entities/UserGroup';
|
import { UserGroup } from '../entities/UserGroup';
|
||||||
|
|
||||||
export class CreateUserGroup {
|
export class CreateUserGroup {
|
||||||
@IsOptional()
|
/**
|
||||||
|
* The new group's name.
|
||||||
|
*/
|
||||||
@IsString()
|
@IsString()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The new group's description.
|
||||||
|
* Optinal.
|
||||||
|
*/
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts this to a UserGroup entity.
|
||||||
|
*/
|
||||||
public async toUserGroup(): Promise<UserGroup> {
|
public async toUserGroup(): Promise<UserGroup> {
|
||||||
let newUserGroup: UserGroup = new UserGroup();
|
let newUserGroup: UserGroup = new UserGroup();
|
||||||
|
|
||||||
if (this.name === undefined) {
|
newUserGroup.name = this.name;
|
||||||
throw new GroupNameNeededError();
|
newUserGroup.description = this.description;
|
||||||
}
|
|
||||||
|
|
||||||
newUserGroup.name = this.name
|
|
||||||
if (this.description) {
|
|
||||||
newUserGroup.description = this.description
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(newUserGroup)
|
|
||||||
return newUserGroup;
|
return newUserGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user