@koalarx/nest 3.1.8 → 3.1.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.
|
@@ -13,7 +13,7 @@ export declare abstract class RepositoryBase<TEntity extends EntityBase<TEntity>
|
|
|
13
13
|
protected _context: TContext;
|
|
14
14
|
private readonly _modelName;
|
|
15
15
|
private readonly _includeFindMany?;
|
|
16
|
-
constructor({ context, modelName
|
|
16
|
+
constructor({ context, modelName }: RepositoryInitProps<TEntity, TContext>);
|
|
17
17
|
private getConnectPrismaSchemaForRelation;
|
|
18
18
|
private getSelectRootPrismaSchema;
|
|
19
19
|
private getPropNameFromEntitySource;
|
|
@@ -12,7 +12,7 @@ class RepositoryBase {
|
|
|
12
12
|
_context;
|
|
13
13
|
_modelName;
|
|
14
14
|
_includeFindMany;
|
|
15
|
-
constructor({ context, modelName
|
|
15
|
+
constructor({ context, modelName }) {
|
|
16
16
|
this._context = context;
|
|
17
17
|
this._modelName = modelName;
|
|
18
18
|
this._includeFindMany = (0, generate_prisma_include_schema_1.generateIncludeSchema)({
|
|
@@ -207,11 +207,13 @@ class RepositoryBase {
|
|
|
207
207
|
async enrichEntityWithRelations(entity) {
|
|
208
208
|
const relationQueries = [];
|
|
209
209
|
const relationKeys = [];
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
const allProps = auto_mapping_list_1.AutoMappingList.getAllProps(this._modelName);
|
|
211
|
+
allProps.forEach((prop) => {
|
|
212
|
+
const propName = prop.name;
|
|
213
|
+
const propDef = auto_mapping_list_1.AutoMappingList.getPropDefinitions(this._modelName.prototype, propName);
|
|
212
214
|
if (propDef) {
|
|
213
|
-
relationKeys.push(
|
|
214
|
-
relationQueries.push(this.loadRelationForEntity(entity[this.getIdPropName()],
|
|
215
|
+
relationKeys.push(propName);
|
|
216
|
+
relationQueries.push(this.loadRelationForEntity(entity[this.getIdPropName()], propName));
|
|
215
217
|
}
|
|
216
218
|
});
|
|
217
219
|
if (relationQueries.length > 0) {
|
|
@@ -289,30 +291,22 @@ class RepositoryBase {
|
|
|
289
291
|
return this.createEntity(enrichedEntity);
|
|
290
292
|
}
|
|
291
293
|
async findFirst(where) {
|
|
292
|
-
|
|
293
|
-
.findFirst({
|
|
294
|
-
include: this.getInclude(),
|
|
294
|
+
const entity = await this.context().findFirst({
|
|
295
295
|
where,
|
|
296
|
-
})
|
|
297
|
-
.then((response) => {
|
|
298
|
-
if (response) {
|
|
299
|
-
return this.createEntity(response);
|
|
300
|
-
}
|
|
301
|
-
return null;
|
|
302
296
|
});
|
|
297
|
+
if (!entity)
|
|
298
|
+
return null;
|
|
299
|
+
const enrichedEntity = await this.enrichEntityWithRelations(entity);
|
|
300
|
+
return this.createEntity(enrichedEntity);
|
|
303
301
|
}
|
|
304
302
|
async findUnique(where) {
|
|
305
|
-
|
|
306
|
-
.findUnique({
|
|
307
|
-
include: this.getInclude(),
|
|
303
|
+
const entity = await this.context().findUnique({
|
|
308
304
|
where,
|
|
309
|
-
})
|
|
310
|
-
.then((response) => {
|
|
311
|
-
if (response) {
|
|
312
|
-
return this.createEntity(response);
|
|
313
|
-
}
|
|
314
|
-
return null;
|
|
315
305
|
});
|
|
306
|
+
if (!entity)
|
|
307
|
+
return null;
|
|
308
|
+
const enrichedEntity = await this.enrichEntityWithRelations(entity);
|
|
309
|
+
return this.createEntity(enrichedEntity);
|
|
316
310
|
}
|
|
317
311
|
async findMany(where, pagination) {
|
|
318
312
|
return this.context()
|
|
@@ -20,6 +20,7 @@ export declare class AutoMappingList {
|
|
|
20
20
|
compositionType?: () => Type<any> | ArrayConstructor;
|
|
21
21
|
compositionAction?: "onlySet" | "addTo";
|
|
22
22
|
} | undefined;
|
|
23
|
+
static getAllProps(source: Type<any>): import("./auto-mapping-class-context").AutoMappingClassProp[];
|
|
23
24
|
static getTargets(source: Type<any>): Type<any>[];
|
|
24
25
|
static addMappedProp(source: Type<any>, propName: string): void;
|
|
25
26
|
static addExtendedPropsIntoSubClass(source: Type<any>): void;
|
|
@@ -50,6 +50,11 @@ class AutoMappingList {
|
|
|
50
50
|
type: (0, get_type_by_prop_1.getTypeByProp)(prop),
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
+
static getAllProps(source) {
|
|
54
|
+
this.initializeLists();
|
|
55
|
+
const mappedClass = this._mappedPropList.find((mp) => mp.source.name === source.name);
|
|
56
|
+
return mappedClass?.props.toArray() ?? [];
|
|
57
|
+
}
|
|
53
58
|
static getTargets(source) {
|
|
54
59
|
this.initializeLists();
|
|
55
60
|
return this._mappingProfileList.filter((mp) => mp.source.name === source.name ||
|