28
src/models/creation/CreateUserGroup.ts
Normal file
28
src/models/creation/CreateUserGroup.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
|
||||
import {
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Permission } from "./Permission";
|
||||
|
||||
/**
|
||||
* Defines the UserGroup interface.
|
||||
*/
|
||||
@Entity()
|
||||
export abstract class UserGroup {
|
||||
export class UserGroup {
|
||||
/**
|
||||
* Autogenerated unique id (primary key).
|
||||
*/
|
||||
@@ -37,7 +37,7 @@ export abstract class UserGroup {
|
||||
/**
|
||||
* The group's description
|
||||
*/
|
||||
@Column({nullable: true})
|
||||
@Column({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
Reference in New Issue
Block a user