This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
/
InvoiceDTO.ts
166 lines (160 loc) · 5.13 KB
/
InvoiceDTO.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (c) 2022. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.
import { isBoolean } from "../../../types/Boolean";
import { isInvoiceRowDTO, InvoiceRowDTO } from "./InvoiceRowDTO";
import { isBooleanOrUndefined } from "../../../types/Boolean";
import { isString } from "../../../types/String";
import { isNumber } from "../../../types/Number";
import { isRegularObject } from "../../../types/RegularObject";
import { hasNoOtherKeysInDevelopment } from "../../../types/OtherKeys";
import { isArrayOfOrUndefined } from "../../../types/Array";
export interface InvoiceDTO {
readonly invoiceId : string;
readonly clientId : string;
readonly campaignId : string;
readonly groupId : string;
readonly bankAccountId : string;
readonly wcOrderId : string;
readonly updated : string;
readonly created : string;
readonly date : string;
readonly dueDate : string;
readonly remindDate : string;
readonly checkoutDate : string;
readonly referenceNumber : string;
readonly internalNote : string;
readonly extraNotice : string;
readonly webSecret : string;
readonly checkoutStamp : string;
readonly onHold : boolean;
readonly isReminded : boolean;
readonly onCollection : boolean;
readonly isTerminated : boolean;
readonly buildDocuments : boolean;
readonly sendDocuments : boolean;
readonly dueDays : number;
readonly rows ?: readonly InvoiceRowDTO[];
readonly isPaid ?: boolean | undefined;
}
export function createInvoiceDTO (
invoiceId : string,
clientId : string,
campaignId : string,
groupId : string,
bankAccountId : string,
wcOrderId : string,
updated : string,
created : string,
date : string,
dueDate : string,
remindDate : string,
checkoutDate : string,
referenceNumber : string,
internalNote : string,
extraNotice : string,
webSecret : string,
checkoutStamp : string,
onHold : boolean,
isReminded : boolean,
onCollection : boolean,
isTerminated : boolean,
buildDocuments : boolean,
sendDocuments : boolean,
dueDays : number,
rows ?: readonly InvoiceRowDTO[],
isPaid ?: boolean
): InvoiceDTO {
return {
invoiceId,
clientId,
campaignId,
groupId,
bankAccountId,
wcOrderId,
updated,
created,
date,
dueDate,
remindDate,
checkoutDate,
referenceNumber,
internalNote,
extraNotice,
webSecret,
checkoutStamp,
onHold,
isReminded,
onCollection,
isTerminated,
buildDocuments,
sendDocuments,
dueDays,
rows,
isPaid
};
}
export function isInvoiceDTO (value: any): value is InvoiceDTO {
return (
isRegularObject(value)
&& hasNoOtherKeysInDevelopment(value, [
'invoiceId',
'clientId',
'campaignId',
'groupId',
'bankAccountId',
'wcOrderId',
'updated',
'created',
'date',
'dueDate',
'remindDate',
'checkoutDate',
'referenceNumber',
'internalNote',
'extraNotice',
'webSecret',
'checkoutStamp',
'onHold',
'isReminded',
'onCollection',
'isTerminated',
'isPaid',
'buildDocuments',
'sendDocuments',
'dueDays',
'rows'
])
&& isString(value?.invoiceId)
&& isString(value?.clientId)
&& isString(value?.campaignId)
&& isString(value?.groupId)
&& isString(value?.bankAccountId)
&& isString(value?.wcOrderId)
&& isString(value?.updated)
&& isString(value?.created)
&& isString(value?.date)
&& isString(value?.dueDate)
&& isString(value?.remindDate)
&& isString(value?.checkoutDate)
&& isString(value?.referenceNumber)
&& isString(value?.internalNote)
&& isString(value?.extraNotice)
&& isString(value?.webSecret)
&& isString(value?.checkoutStamp)
&& isBoolean(value?.onHold)
&& isBoolean(value?.isReminded)
&& isBoolean(value?.onCollection)
&& isBoolean(value?.isTerminated)
&& isBooleanOrUndefined(value?.isPaid)
&& isBoolean(value?.buildDocuments)
&& isBoolean(value?.sendDocuments)
&& isNumber(value?.dueDays)
&& isArrayOfOrUndefined<InvoiceRowDTO>(value?.rows, isInvoiceRowDTO)
);
}
export function stringifyInvoiceDTO (value: InvoiceDTO): string {
return `InvoiceDTO(${value})`;
}
export function parseInvoiceDTO (value: any): InvoiceDTO | undefined {
if ( isInvoiceDTO(value) ) return value;
return undefined;
}