67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
import { IsEmail, IsNotEmpty, IsObject, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
|
import { config } from '../../../config';
|
|
import { Address } from '../../entities/Address';
|
|
import { GroupContact } from '../../entities/GroupContact';
|
|
|
|
/**
|
|
* This classed is used to create a new Group entity from a json body (post request).
|
|
*/
|
|
export class CreateGroupContact {
|
|
/**
|
|
* The new contact's first name.
|
|
*/
|
|
@IsNotEmpty()
|
|
@IsString()
|
|
firstname: string;
|
|
|
|
/**
|
|
* The new contact's middle name.
|
|
*/
|
|
@IsOptional()
|
|
@IsString()
|
|
middlename?: string;
|
|
|
|
/**
|
|
* The new contact's last name.
|
|
*/
|
|
@IsNotEmpty()
|
|
@IsString()
|
|
lastname: string;
|
|
|
|
/**
|
|
* The new contact's address.
|
|
*/
|
|
@IsOptional()
|
|
@IsObject()
|
|
address?: Address;
|
|
|
|
/**
|
|
* The contact's phone number.
|
|
* This will be validated against the configured country phone numer syntax (default: international).
|
|
*/
|
|
@IsOptional()
|
|
@IsPhoneNumber(config.phone_validation_countrycode)
|
|
phone?: string;
|
|
|
|
/**
|
|
* The contact's email address.
|
|
*/
|
|
@IsOptional()
|
|
@IsEmail()
|
|
email?: string;
|
|
|
|
|
|
/**
|
|
* Creates a new Address entity from this.
|
|
*/
|
|
public async toEntity(): Promise<GroupContact> {
|
|
let contact: GroupContact = new GroupContact();
|
|
contact.firstname = this.firstname;
|
|
contact.middlename = this.middlename;
|
|
contact.lastname = this.lastname;
|
|
contact.email = this.email;
|
|
contact.phone = this.phone;
|
|
contact.address = this.address;
|
|
return null;
|
|
}
|
|
} |