@koalarx/nest 3.1.42 → 3.1.43

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.
@@ -34,6 +34,8 @@ export declare abstract class RepositoryBase<TEntity extends EntityBase<TEntity>
34
34
  private loadEntityFromCache;
35
35
  private enrichEntityWithRelations;
36
36
  private persistRelations;
37
+ private setIdOnEntity;
38
+ private autofillCreatedId;
37
39
  protected context(transactionalClient?: TContext): TContext[TModelKey];
38
40
  protected findById(id: IComparableId): Promise<TEntity | null>;
39
41
  protected findFirst<T>(where: T): Promise<TEntity | null>;
@@ -489,6 +489,37 @@ class RepositoryBase {
489
489
  ]);
490
490
  }
491
491
  }
492
+ setIdOnEntity(entityInstance, data) {
493
+ const idPropName = this.getIdPropName(entityInstance);
494
+ if (!Array.isArray(idPropName)) {
495
+ entityInstance[idPropName] = data[idPropName];
496
+ entityInstance._id = data[idPropName];
497
+ }
498
+ else {
499
+ idPropName.forEach((propName) => {
500
+ entityInstance[propName] = data[propName];
501
+ });
502
+ entityInstance._id = idPropName.map((name) => data[name]).join('-');
503
+ }
504
+ entityInstance._action = entity_base_1.EntityActionType.update;
505
+ entityInstance._hasUpdate = false;
506
+ }
507
+ autofillCreatedId(entity, response) {
508
+ const entityProps = auto_mapping_list_1.AutoMappingList.getAllProps(entity.constructor);
509
+ this.setIdOnEntity(entity, response);
510
+ entityProps.forEach((prop) => {
511
+ let instance;
512
+ try {
513
+ instance = new (prop.type())();
514
+ }
515
+ catch {
516
+ instance = null;
517
+ }
518
+ if (instance instanceof entity_base_1.EntityBase) {
519
+ this.setIdOnEntity(entity[prop.name], response[prop.name]);
520
+ }
521
+ });
522
+ }
492
523
  context(transactionalClient) {
493
524
  const modelName = this._modelName.name;
494
525
  if (!modelName)
@@ -556,18 +587,10 @@ class RepositoryBase {
556
587
  return this.withTransaction((client) => this.context(client)
557
588
  .create({
558
589
  data: prismaEntity,
559
- include: this.getInclude(),
590
+ select: this.getSelectRootPrismaSchema(entity.constructor),
560
591
  })
561
592
  .then((response) => {
562
- const idPropName = this.getIdPropName(entity);
563
- if (!Array.isArray(idPropName)) {
564
- entity[idPropName] = response[idPropName];
565
- }
566
- else {
567
- idPropName.forEach((propName) => {
568
- entity[propName] = response[propName];
569
- });
570
- }
593
+ this.autofillCreatedId(entity, response);
571
594
  return this.persistRelations(client, entity).then(() => entity);
572
595
  }));
573
596
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "3.1.42",
3
+ "version": "3.1.43",
4
4
  "description": "",
5
5
  "author": "Igor D. Rangel",
6
6
  "license": "MIT",