framework-do-dede 6.0.6 → 6.1.0
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.
|
@@ -9,7 +9,7 @@ export declare abstract class Model<TEntity extends Entity = Entity> extends Rep
|
|
|
9
9
|
[property: string]: any;
|
|
10
10
|
fromModel(input: Record<string, any> | null | undefined): this;
|
|
11
11
|
abstract fromEntity(entity: TEntity): this;
|
|
12
|
-
toModel(): Record<string, any>;
|
|
12
|
+
toModel(ignoreId?: boolean, namedId?: string): Record<string, any>;
|
|
13
13
|
abstract toEntity(): TEntity;
|
|
14
14
|
}
|
|
15
15
|
export declare function column(columnName: string): (target: any, propertyKey: string) => void;
|
|
@@ -12,10 +12,11 @@ export class Model extends RepositoryModel {
|
|
|
12
12
|
}
|
|
13
13
|
return this;
|
|
14
14
|
}
|
|
15
|
-
toModel() {
|
|
15
|
+
toModel(ignoreId = false, namedId) {
|
|
16
16
|
const record = {};
|
|
17
17
|
const columns = this.columns ?? [];
|
|
18
18
|
const mappedProperties = new Set();
|
|
19
|
+
const idColumn = columns.find((column) => column.property === "id")?.column ?? "id";
|
|
19
20
|
for (const column of columns) {
|
|
20
21
|
record[column.column] = this[column.property];
|
|
21
22
|
mappedProperties.add(column.property);
|
|
@@ -29,6 +30,13 @@ export class Model extends RepositoryModel {
|
|
|
29
30
|
}
|
|
30
31
|
record[property] = this[property];
|
|
31
32
|
}
|
|
33
|
+
const idValue = this.id ?? record[idColumn];
|
|
34
|
+
if (namedId && idValue !== undefined) {
|
|
35
|
+
record[namedId] = idValue;
|
|
36
|
+
}
|
|
37
|
+
if (ignoreId) {
|
|
38
|
+
delete record[idColumn];
|
|
39
|
+
}
|
|
32
40
|
return record;
|
|
33
41
|
}
|
|
34
42
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare abstract class RepositoryModel<TEntity = any> {
|
|
2
2
|
abstract fromModel(input: Record<string, any> | null | undefined): this;
|
|
3
|
-
abstract toModel(): Record<string, any>;
|
|
3
|
+
abstract toModel(ignoreId?: boolean, namedId?: string): Record<string, any>;
|
|
4
4
|
abstract fromEntity(entity: TEntity): this;
|
|
5
5
|
abstract toEntity(): TEntity;
|
|
6
6
|
}
|