-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentityCopier.ts
More file actions
39 lines (35 loc) · 1020 Bytes
/
Copy pathentityCopier.ts
File metadata and controls
39 lines (35 loc) · 1020 Bytes
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
export class EntityCopier {
static Copy<T>(s: any, d: T): T {
delete (<any>d).sqlTemp;
delete (<any>d).ctx;
delete (<any>d).queryParam;
for (let key in d) {
if (s[key] == undefined || s[key] == null) continue;
if (typeof (s[key]) != "function")
d[key] = s[key];
if (s[key] instanceof Date) {
d[key] = s[key];
}
else if (typeof (s[key]) == "object") {
d[<any>key] = JSON.stringify(s[key]);
}
}
return d;
}
static Decode<T>(s: any) {
delete (<any>s).sqlTemp;
delete (<any>s).ctx;
delete (<any>s).queryParam;
delete (<any>s).joinParams;
for (let key in s) {
try {
let d = JSON.parse(s[key]);
if (isNaN(d) || Array.isArray(d)) {
s[key] = d;
}
}
catch (err) { }
}
return s;
}
}