This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
/
NewClientDTO.ts
58 lines (53 loc) · 2.4 KB
/
NewClientDTO.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2020-2022. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.
import { isBooleanOrUndefined } from "../../../types/Boolean";
import { isString, isStringOrUndefined } from "../../../types/String";
import { isRegularObject } from "../../../types/RegularObject";
import { isArrayOrUndefinedOf } from "../../../types/Array";
/**
* The client object used in the REST API communication when creating a new client record
*/
export interface NewClientDTO {
readonly company ?: string;
readonly companyCode ?: string;
readonly firstName ?: string;
readonly lastName ?: string;
readonly address ?: string | string[];
readonly postCode ?: string;
readonly postName ?: string;
readonly country ?: string;
readonly email ?: string | string[];
readonly phone ?: string;
readonly mobile ?: string;
readonly fax ?: string;
readonly billingLang ?: string;
readonly sendEmail ?: boolean;
readonly sendPost ?: boolean;
}
export function isNewClientDTO (value: any): value is NewClientDTO {
return (
isRegularObject(value)
&& isStringOrUndefined(value?.company)
&& isStringOrUndefined(value?.companyCode)
&& isStringOrUndefined(value?.firstName)
&& isStringOrUndefined(value?.lastName)
&& (isString(value?.address) || isArrayOrUndefinedOf<string>(value?.address, isString))
&& isStringOrUndefined(value?.postCode)
&& isStringOrUndefined(value?.postName)
&& isStringOrUndefined(value?.country)
&& (isString(value?.email) || isArrayOrUndefinedOf<string>(value?.email, isString))
&& isStringOrUndefined(value?.phone)
&& isStringOrUndefined(value?.mobile)
&& isStringOrUndefined(value?.fax)
&& isStringOrUndefined(value?.billingLang)
&& isBooleanOrUndefined(value?.sendEmail)
&& isBooleanOrUndefined(value?.sendPost)
);
}
export function stringifyNewClientDTO (value: NewClientDTO): string {
if ( !isNewClientDTO(value) ) throw new TypeError(`Not NewClientDTO: ${value}`);
return `NewClientDTO(${value})`;
}
export function parseNewClientDTO (value: any): NewClientDTO | undefined {
if ( isNewClientDTO(value) ) return value;
return undefined;
}