@koalarx/nest 3.1.19 → 3.1.21
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.
|
@@ -108,19 +108,26 @@ class RepositoryBase {
|
|
|
108
108
|
return selectSchema;
|
|
109
109
|
}
|
|
110
110
|
getPropNameFromEntitySource(source, entity) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
const entityProps = auto_mapping_list_1.AutoMappingList.getAllProps(source);
|
|
112
|
+
return entityProps.find((prop) => {
|
|
113
|
+
let instance;
|
|
114
|
+
try {
|
|
115
|
+
instance = new (prop.type())();
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
instance = null;
|
|
119
|
+
}
|
|
120
|
+
if (instance) {
|
|
121
|
+
if (instance.constructor.name === entity.name) {
|
|
115
122
|
return true;
|
|
116
123
|
}
|
|
117
|
-
else if (source[
|
|
118
|
-
const list = source[
|
|
124
|
+
else if (source[prop.name] instanceof list_1.List) {
|
|
125
|
+
const list = source[prop.name];
|
|
119
126
|
return list.entityType?.name === entity.name;
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
return false;
|
|
123
|
-
});
|
|
130
|
+
})?.name;
|
|
124
131
|
}
|
|
125
132
|
listRelationEntities(entity, fromList = false) {
|
|
126
133
|
const relationEntities = [];
|
|
@@ -150,13 +157,13 @@ class RepositoryBase {
|
|
|
150
157
|
const entityInstance = list.entityType;
|
|
151
158
|
const modelName = entityInstance.name;
|
|
152
159
|
const parentModelName = entity.constructor.name;
|
|
153
|
-
const parentPropName = this.getPropNameFromEntitySource(
|
|
160
|
+
const parentPropName = this.getPropNameFromEntitySource(entityInstance, entity.constructor) ?? (0, KlString_1.toCamelCase)(parentModelName);
|
|
154
161
|
if (modelName) {
|
|
155
162
|
list.toArray('removed').forEach((item) => {
|
|
156
163
|
relationDeletes.push({
|
|
157
164
|
modelName: (0, KlString_1.toCamelCase)(modelName),
|
|
158
165
|
entityInstance,
|
|
159
|
-
schema:
|
|
166
|
+
schema: this.getWhereByIdSchema(item, item),
|
|
160
167
|
relations: [],
|
|
161
168
|
});
|
|
162
169
|
});
|
|
@@ -179,7 +186,7 @@ class RepositoryBase {
|
|
|
179
186
|
modelName: (0, KlString_1.toCamelCase)(modelName),
|
|
180
187
|
entityInstance,
|
|
181
188
|
schema: {
|
|
182
|
-
where:
|
|
189
|
+
where: this.getWhereByIdSchema(item, item),
|
|
183
190
|
data: this.entityToPrisma(item),
|
|
184
191
|
select: this.getSelectRootPrismaSchema(item.constructor),
|
|
185
192
|
},
|
|
@@ -375,9 +382,9 @@ class RepositoryBase {
|
|
|
375
382
|
return this.persistRelations(transaction, relation);
|
|
376
383
|
});
|
|
377
384
|
}));
|
|
378
|
-
})),
|
|
379
|
-
|
|
380
|
-
|
|
385
|
+
}), ...relationUpdates.map((relation) => transaction[relation.modelName].update(relation.schema)), ...relationDeletes.map((relation) => transaction[relation.modelName].deleteMany({
|
|
386
|
+
where: relation.schema,
|
|
387
|
+
}))),
|
|
381
388
|
]);
|
|
382
389
|
}
|
|
383
390
|
context(transactionalClient) {
|