@koalarx/nest 3.0.9 → 3.0.10

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.
@@ -19,6 +19,8 @@ export declare abstract class RepositoryBase<TEntity extends EntityBase<TEntity>
19
19
  private readonly _modelName;
20
20
  private readonly _include?;
21
21
  constructor({ context, modelName, include, }: RepositoryInitProps<TEntity, TContext>);
22
+ private getConnectPrismaSchemaForRelation;
23
+ private getSelectRootPrismaSchema;
22
24
  private getPropNameFromEntitySource;
23
25
  private listRelationEntities;
24
26
  private listToRelationActionList;
@@ -16,6 +16,31 @@ class RepositoryBase {
16
16
  this._modelName = modelName;
17
17
  this._include = include;
18
18
  }
19
+ getConnectPrismaSchemaForRelation(entity, data) {
20
+ const propIdName = this.getIdPropName(entity);
21
+ return {
22
+ connect: {
23
+ [propIdName]: (data ?? entity)[propIdName],
24
+ },
25
+ };
26
+ }
27
+ getSelectRootPrismaSchema(entity) {
28
+ const selectSchema = {};
29
+ Object.keys(entity)
30
+ .filter((key) => !['id', '_id', '_action'].includes(key))
31
+ .filter((key) => !(entity[key] instanceof Function || entity[key] instanceof list_1.List))
32
+ .forEach((key) => {
33
+ if (entity[key] instanceof entity_base_1.EntityBase) {
34
+ selectSchema[key] = {
35
+ select: this.getSelectRootPrismaSchema(entity[key]),
36
+ };
37
+ }
38
+ else {
39
+ selectSchema[key] = true;
40
+ }
41
+ });
42
+ return selectSchema;
43
+ }
19
44
  getPropNameFromEntitySource(source, entity) {
20
45
  return Object.keys(source).find((key) => {
21
46
  const propDefinitions = auto_mapping_list_1.AutoMappingList.getPropDefinitions(source.constructor, key);
@@ -76,12 +101,9 @@ class RepositoryBase {
76
101
  schema: {
77
102
  data: {
78
103
  ...this.entityToPrisma(item),
79
- [parentPropName]: {
80
- connect: {
81
- [this.getIdPropName(entity)]: entity[this.getIdPropName(entity)],
82
- },
83
- },
104
+ [parentPropName]: this.getConnectPrismaSchemaForRelation(entity),
84
105
  },
106
+ select: this.getSelectRootPrismaSchema(item),
85
107
  },
86
108
  relations: this.listRelationEntities(item),
87
109
  });
@@ -93,6 +115,7 @@ class RepositoryBase {
93
115
  schema: {
94
116
  where: { id: item._id },
95
117
  data: this.entityToPrisma(item),
118
+ select: this.getSelectRootPrismaSchema(item),
96
119
  },
97
120
  relations: this.listRelationEntities(item),
98
121
  });
@@ -187,14 +210,13 @@ class RepositoryBase {
187
210
  return Promise.all(relationCreate.relations.map((relation) => {
188
211
  const relationPropName = this.getPropNameFromEntitySource(relation, relationCreate.entityInstance);
189
212
  if (relationPropName) {
190
- const relationEntity = this.createEntity(response, relationCreate.entityInstance);
191
- relationEntity._action = entity_base_1.EntityActionType.create;
192
- relation[relationPropName] = relationEntity;
213
+ relation[relationPropName] =
214
+ this.getConnectPrismaSchemaForRelation(relationCreate.entityInstance, response);
193
215
  }
194
216
  return transaction[(0, KlString_1.toCamelCase)(relation.constructor.name)]
195
217
  .create({
196
218
  data: this.entityToPrisma(relation),
197
- select: { [this.getIdPropName(relation)]: true },
219
+ select: this.getSelectRootPrismaSchema(relation),
198
220
  })
199
221
  .then((response) => {
200
222
  relation[this.getIdPropName(relation)] =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "3.0.9",
3
+ "version": "3.0.10",
4
4
  "description": "",
5
5
  "author": "Igor D. Rangel",
6
6
  "license": "MIT",