-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContactNode.ts
52 lines (44 loc) · 1.32 KB
/
ContactNode.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
import { Element } from '../Element';
import { isBoolean, isEnum, isObject, isUuid } from '../validation';
interface NewsroomContact {
uuid: string;
}
export interface ContactNode extends Element<typeof ContactNode.TYPE> {
uuid: string;
reference: NewsroomContact['uuid'] | null;
contact: ContactNode.ContactInfo;
layout: `${ContactNode.Layout}`;
show_avatar: boolean;
}
export namespace ContactNode {
export const TYPE = 'contact';
export interface ContactInfo {
avatar_url: string | null;
name: string;
company: string;
description: string;
email: string;
website: string;
phone: string;
mobile: string;
twitter: string;
facebook: string;
address: string;
}
export enum Layout {
CARD = 'card',
SIGNATURE = 'signature',
}
export function isContactNode(value: any): value is ContactNode {
return Element.isElement(value, TYPE);
}
export function validateContactNode(value: any): ContactNode | null {
const isValid =
isContactNode(value) &&
isUuid(value.uuid) &&
isObject(value.contact) &&
isEnum(value.layout, ContactNode.Layout) &&
isBoolean(value.show_avatar);
return isValid ? value : null;
}
}