framework-do-dede 5.2.0 → 5.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Entity } from "../../application";
|
|
1
2
|
export type ColumnDefinition = {
|
|
2
3
|
column: string;
|
|
3
4
|
property: string;
|
|
@@ -6,7 +7,9 @@ export declare abstract class Model<TTable = string> {
|
|
|
6
7
|
table: TTable;
|
|
7
8
|
columns: ColumnDefinition[];
|
|
8
9
|
[property: string]: any;
|
|
9
|
-
|
|
10
|
+
constructor(input?: Record<string, any> | Entity);
|
|
11
|
+
toModel(): Record<string, any>;
|
|
12
|
+
abstract toEntity(): Entity;
|
|
10
13
|
}
|
|
11
14
|
export declare function model<TTable>(table: TTable): (target: any) => void;
|
|
12
15
|
export declare function column(columnName: string): (target: any, propertyKey: string) => void;
|
|
@@ -1,9 +1,35 @@
|
|
|
1
|
+
import { Entity } from "../../application";
|
|
1
2
|
export class Model {
|
|
2
|
-
|
|
3
|
+
constructor(input) {
|
|
4
|
+
if (!input)
|
|
5
|
+
return;
|
|
6
|
+
let data = {};
|
|
7
|
+
if (input instanceof Entity) {
|
|
8
|
+
data = input.from();
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
data = input;
|
|
12
|
+
}
|
|
13
|
+
for (const [property, value] of Object.entries(data)) {
|
|
14
|
+
this[property] = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
toModel() {
|
|
3
18
|
const record = {};
|
|
4
19
|
const columns = this.columns ?? [];
|
|
20
|
+
const mappedProperties = new Set();
|
|
5
21
|
for (const column of columns) {
|
|
6
22
|
record[column.column] = this[column.property];
|
|
23
|
+
mappedProperties.add(column.property);
|
|
24
|
+
}
|
|
25
|
+
for (const property of Object.keys(this)) {
|
|
26
|
+
if (property === "table" || property === "columns") {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (mappedProperties.has(property)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
record[property] = this[property];
|
|
7
33
|
}
|
|
8
34
|
return record;
|
|
9
35
|
}
|