@punks/backend-entity-manager 0.0.170 → 0.0.171

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.
package/dist/cjs/index.js CHANGED
@@ -22260,6 +22260,9 @@ class TypeOrmQueryBuilder extends QueryBuilderBase {
22260
22260
  const facets = request.options?.includeFacets
22261
22261
  ? await this.calculateFacets(request, context)
22262
22262
  : undefined;
22263
+ const childrenMap = request.options?.includeChildrenMap
22264
+ ? await this.calculateChildrenMap(results)
22265
+ : undefined;
22263
22266
  return {
22264
22267
  items: results,
22265
22268
  request,
@@ -22269,6 +22272,7 @@ class TypeOrmQueryBuilder extends QueryBuilderBase {
22269
22272
  totResults: queryResults,
22270
22273
  }),
22271
22274
  facets,
22275
+ childrenMap,
22272
22276
  };
22273
22277
  }
22274
22278
  async getFieldDistinctValues(field, request, context) {
@@ -22311,6 +22315,29 @@ class TypeOrmQueryBuilder extends QueryBuilderBase {
22311
22315
  value: typeorm.ILike(`%${request.query?.term}%`),
22312
22316
  }));
22313
22317
  }
22318
+ calculateChildrenMap(items) {
22319
+ return Promise.resolve({});
22320
+ }
22321
+ async queryChildrenMap({ nodeIds, idField, parentField, }) {
22322
+ const result = await this.getRepository()
22323
+ .getInnerRepository()
22324
+ .createQueryBuilder("entity")
22325
+ .where({
22326
+ [parentField.toString()]: {
22327
+ [idField.toString()]: typeorm.In(nodeIds),
22328
+ },
22329
+ })
22330
+ .select(`entity.${parentField.toString()}.${idField.toString()}`, "parentId")
22331
+ .addSelect(`COUNT(entity.${idField.toString()})`, "count")
22332
+ .groupBy(`entity.${parentField.toString()}.${idField.toString()}`)
22333
+ .getRawMany();
22334
+ return result.reduce((acc, x) => {
22335
+ acc[x.parentId] = {
22336
+ count: parseInt(x.count),
22337
+ };
22338
+ return acc;
22339
+ }, {});
22340
+ }
22314
22341
  async calculateFacet(field, request, context, relations) {
22315
22342
  let query = this.getRepository()
22316
22343
  .getInnerRepository()