backend/src/models/actions/CreateUserGroup.ts

33 lines
749 B
TypeScript
Raw Normal View History

2020-12-04 17:34:14 +00:00
import { IsOptional, IsString } from 'class-validator';
import { UserGroup } from '../entities/UserGroup';
/**
* This classed is used to create a new UserGroup entity from a json body (post request).
*/
2020-12-04 17:34:14 +00:00
export class CreateUserGroup {
/**
* The new group's name.
*/
2020-12-04 17:34:14 +00:00
@IsString()
name: string;
/**
* The new group's description.
* Optinal.
*/
2020-12-04 17:34:14 +00:00
@IsOptional()
@IsString()
description?: string;
/**
* Creates a new UserGroup entity from this.
*/
2020-12-04 17:34:14 +00:00
public async toUserGroup(): Promise<UserGroup> {
let newUserGroup: UserGroup = new UserGroup();
newUserGroup.name = this.name;
newUserGroup.description = this.description;
2020-12-04 17:34:14 +00:00
return newUserGroup;
}
}