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