@koalarx/nest 3.1.24 → 3.1.26
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.
|
@@ -348,44 +348,54 @@ class RepositoryBase {
|
|
|
348
348
|
}
|
|
349
349
|
return data;
|
|
350
350
|
}
|
|
351
|
-
persistRelations(transaction, entity) {
|
|
351
|
+
async persistRelations(transaction, entity) {
|
|
352
352
|
const { relationCreates, relationUpdates, relationDeletes } = this.listToRelationActionList(entity);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
353
|
+
if (relationDeletes.length > 0) {
|
|
354
|
+
await Promise.all(relationDeletes.map((relation) => transaction[relation.modelName].deleteMany({
|
|
355
|
+
where: relation.schema,
|
|
356
|
+
})));
|
|
357
|
+
}
|
|
358
|
+
if (relationUpdates.length > 0) {
|
|
359
|
+
await Promise.all([
|
|
360
|
+
...relationUpdates.map((relation) => transaction[relation.modelName].update(relation.schema)),
|
|
361
|
+
]);
|
|
362
|
+
}
|
|
363
|
+
if (relationCreates.length > 0) {
|
|
364
|
+
await Promise.all([
|
|
365
|
+
...relationCreates.map((relationCreate) => transaction[relationCreate.modelName]
|
|
366
|
+
.create(relationCreate.schema)
|
|
367
|
+
.then((response) => {
|
|
368
|
+
if (relationCreate.relations.length === 0) {
|
|
369
|
+
return Promise.all([]);
|
|
368
370
|
}
|
|
369
|
-
return
|
|
370
|
-
.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const idPropName = this.getIdPropName(relation);
|
|
376
|
-
if (!Array.isArray(idPropName)) {
|
|
377
|
-
relation[idPropName] = response[idPropName];
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
idPropName.forEach((propName) => {
|
|
381
|
-
relation[propName] = response[propName];
|
|
382
|
-
});
|
|
371
|
+
return Promise.all(relationCreate.relations.map((relation) => {
|
|
372
|
+
const relationPropName = this.getPropNameFromEntitySource(relation, relationCreate.entityInstance);
|
|
373
|
+
if (relationPropName &&
|
|
374
|
+
!(relation[relationPropName] instanceof list_1.List)) {
|
|
375
|
+
relation[relationPropName] =
|
|
376
|
+
this.getConnectPrismaSchemaForRelation(relationCreate.entityInstance, response);
|
|
383
377
|
}
|
|
384
|
-
return
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
378
|
+
return transaction[(0, KlString_1.toCamelCase)(relation.constructor.name)]
|
|
379
|
+
.create({
|
|
380
|
+
data: this.entityToPrisma(relation),
|
|
381
|
+
select: this.getSelectRootPrismaSchema(relation.constructor),
|
|
382
|
+
})
|
|
383
|
+
.then((response) => {
|
|
384
|
+
const idPropName = this.getIdPropName(relation);
|
|
385
|
+
if (!Array.isArray(idPropName)) {
|
|
386
|
+
relation[idPropName] = response[idPropName];
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
idPropName.forEach((propName) => {
|
|
390
|
+
relation[propName] = response[propName];
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
return this.persistRelations(transaction, relation);
|
|
394
|
+
});
|
|
395
|
+
}));
|
|
396
|
+
})),
|
|
397
|
+
]);
|
|
398
|
+
}
|
|
389
399
|
}
|
|
390
400
|
context(transactionalClient) {
|
|
391
401
|
const modelName = this._modelName.name;
|