backend/src/models/responses/ResponseUser.ts
2020-12-18 15:12:06 +01:00

90 lines
1.6 KiB
TypeScript

import {
IsArray,
IsBoolean,
IsOptional,
IsString
} from "class-validator";
import { Permission } from '../entities/Permission';
import { User } from '../entities/User';
import { UserGroup } from '../entities/UserGroup';
import { ResponsePrincipal } from './ResponsePrincipal';
/**
* Defines a user response.
*/
export class ResponseUser extends ResponsePrincipal {
/**
* The user's first name.
*/
@IsString()
firstname: string;
/**
* The user's middle name.
* Optional.
*/
@IsString()
middlename?: string;
/**
* The user's last name.
*/
@IsString()
lastname: string;
/**
* The user's phone number.
* Optional.
*/
@IsString()
phone?: string;
/**
* The user's e-mail address.
* Optional.
*/
@IsString()
email?: string;
/**
* is user enabled?
*/
@IsBoolean()
enabled: boolean = true;
/**
* profilepic
*/
@IsString()
@IsOptional()
profilePic?: string;
/**
* Groups
*/
@IsArray()
@IsOptional()
groups: UserGroup[];
/**
* permissions
*/
@IsArray()
@IsOptional()
permissions: Permission[];
public constructor(user: User) {
super(user);
this.firstname = user.firstname;
this.middlename = user.middlename;
this.lastname = user.lastname;
this.phone = user.phone;
this.email = user.email;
this.enabled = user.enabled;
this.profilePic = user.profilePic;
this.groups = user.groups;
this.permissions = user.permissions;
}
}