@koalarx/nest 3.1.37 → 3.1.39
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.
|
@@ -223,6 +223,17 @@ class RepositoryBase {
|
|
|
223
223
|
relations: this.listRelationEntities(entityInstance),
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
|
+
else if (entity[key]._action === entity_base_1.EntityActionType.create) {
|
|
227
|
+
relationCreates.push({
|
|
228
|
+
modelName: (0, KlString_1.toCamelCase)(modelName),
|
|
229
|
+
entityInstance,
|
|
230
|
+
schema: {
|
|
231
|
+
data: this.entityToPrisma(entityInstance),
|
|
232
|
+
select: this.getSelectRootPrismaSchema(entityInstance.constructor),
|
|
233
|
+
},
|
|
234
|
+
relations: this.listRelationEntities(entityInstance),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
226
237
|
}
|
|
227
238
|
});
|
|
228
239
|
return { relationCreates, relationUpdates, relationDeletes };
|
|
@@ -392,7 +403,35 @@ class RepositoryBase {
|
|
|
392
403
|
return Promise.all([]);
|
|
393
404
|
}
|
|
394
405
|
return Promise.all(relationUpdate.relations.map((relation) => {
|
|
395
|
-
|
|
406
|
+
if (relation._action === entity_base_1.EntityActionType.update &&
|
|
407
|
+
relation._hasUpdate) {
|
|
408
|
+
return this.persistRelations(transaction, relation);
|
|
409
|
+
}
|
|
410
|
+
else if (relation._action === entity_base_1.EntityActionType.create) {
|
|
411
|
+
const relationPropName = this.getPropNameFromEntitySource(relation.constructor, relationUpdate.entityInstance);
|
|
412
|
+
if (relationPropName &&
|
|
413
|
+
!(relation[relationPropName] instanceof list_1.List)) {
|
|
414
|
+
relation[relationPropName] =
|
|
415
|
+
this.getConnectPrismaSchemaForRelation(relationUpdate.entityInstance, entity);
|
|
416
|
+
}
|
|
417
|
+
return transaction[(0, KlString_1.toCamelCase)(relation.constructor.name)]
|
|
418
|
+
.create({
|
|
419
|
+
data: this.entityToPrisma(relation),
|
|
420
|
+
select: this.getSelectRootPrismaSchema(relation.constructor),
|
|
421
|
+
})
|
|
422
|
+
.then((response) => {
|
|
423
|
+
const idPropName = this.getIdPropName(relation);
|
|
424
|
+
if (!Array.isArray(idPropName)) {
|
|
425
|
+
relation[idPropName] = response[idPropName];
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
idPropName.forEach((propName) => {
|
|
429
|
+
relation[propName] = response[propName];
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
return this.persistRelations(transaction, relation);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
396
435
|
}));
|
|
397
436
|
})),
|
|
398
437
|
]);
|