@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
- return Promise.all(relationDeletes.map((relation) => transaction[relation.modelName].deleteMany({
354
- where: relation.schema,
355
- }))).then(() => Promise.all([
356
- ...relationCreates.map((relationCreate) => transaction[relationCreate.modelName]
357
- .create(relationCreate.schema)
358
- .then((response) => {
359
- if (relationCreate.relations.length === 0) {
360
- return Promise.all([]);
361
- }
362
- return Promise.all(relationCreate.relations.map((relation) => {
363
- const relationPropName = this.getPropNameFromEntitySource(relation, relationCreate.entityInstance);
364
- if (relationPropName &&
365
- !(relation[relationPropName] instanceof list_1.List)) {
366
- relation[relationPropName] =
367
- this.getConnectPrismaSchemaForRelation(relationCreate.entityInstance, response);
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 transaction[(0, KlString_1.toCamelCase)(relation.constructor.name)]
370
- .create({
371
- data: this.entityToPrisma(relation),
372
- select: this.getSelectRootPrismaSchema(relation.constructor),
373
- })
374
- .then((response) => {
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 this.persistRelations(transaction, relation);
385
- });
386
- }));
387
- }), ...relationUpdates.map((relation) => transaction[relation.modelName].update(relation.schema))),
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "3.1.24",
3
+ "version": "3.1.26",
4
4
  "description": "",
5
5
  "author": "Igor D. Rangel",
6
6
  "license": "MIT",