@koalarx/nest 3.1.42 → 3.1.44
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,29 @@ 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
|
+
this.setIdOnEntity(entity, response);
|
|
509
|
+
Object.keys(entity).forEach((key) => {
|
|
510
|
+
if (entity[key] instanceof entity_base_1.EntityBase && response[key]) {
|
|
511
|
+
this.setIdOnEntity(entity[key], response[key]);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
}
|
|
492
515
|
context(transactionalClient) {
|
|
493
516
|
const modelName = this._modelName.name;
|
|
494
517
|
if (!modelName)
|
|
@@ -556,18 +579,10 @@ class RepositoryBase {
|
|
|
556
579
|
return this.withTransaction((client) => this.context(client)
|
|
557
580
|
.create({
|
|
558
581
|
data: prismaEntity,
|
|
559
|
-
|
|
582
|
+
select: this.getSelectRootPrismaSchema(entity.constructor),
|
|
560
583
|
})
|
|
561
584
|
.then((response) => {
|
|
562
|
-
|
|
563
|
-
if (!Array.isArray(idPropName)) {
|
|
564
|
-
entity[idPropName] = response[idPropName];
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
idPropName.forEach((propName) => {
|
|
568
|
-
entity[propName] = response[propName];
|
|
569
|
-
});
|
|
570
|
-
}
|
|
585
|
+
this.autofillCreatedId(entity, response);
|
|
571
586
|
return this.persistRelations(client, entity).then(() => entity);
|
|
572
587
|
}));
|
|
573
588
|
}
|
|
@@ -577,8 +592,12 @@ class RepositoryBase {
|
|
|
577
592
|
.update({
|
|
578
593
|
where,
|
|
579
594
|
data: prismaEntity,
|
|
595
|
+
select: this.getSelectRootPrismaSchema(entity.constructor),
|
|
580
596
|
})
|
|
581
|
-
.then(() =>
|
|
597
|
+
.then((response) => {
|
|
598
|
+
this.autofillCreatedId(entity, response);
|
|
599
|
+
return this.persistRelations(client, entity);
|
|
600
|
+
})).then(() => this.findUnique(where));
|
|
582
601
|
}
|
|
583
602
|
}
|
|
584
603
|
async saveMany(entities, updateWhere) {
|