mm-share-lib 0.0.23 → 0.0.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm-share-lib",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "Share the generic service, entity, dto.",
5
5
  "author": "Mesa SOT",
6
6
  "license": "MIT",
@@ -13,6 +13,7 @@ import { BaseDocument } from '../../document';
13
13
  import { SearchDocumentService } from '../../interface';
14
14
  import { EntityGeneric } from '../../../../generic';
15
15
  import { PaginationResponse } from '../../../../response';
16
+ import { BaseFilterDto } from '../../../../dto';
16
17
 
17
18
  export abstract class ClientService<
18
19
  Document extends BaseDocument,
@@ -41,11 +42,13 @@ export abstract class ClientService<
41
42
  async searchDocument(
42
43
  searchParameters: SearchParams,
43
44
  options: SearchOptions,
45
+ filter?: BaseFilterDto,
44
46
  ): Promise<SearchResponse<any>> {
45
47
  return this.searchDocumentByCollection(
46
48
  this.getCollectionName(),
47
49
  searchParameters,
48
50
  options,
51
+ filter,
49
52
  );
50
53
  }
51
54
 
@@ -53,10 +56,12 @@ export abstract class ClientService<
53
56
  collection: string,
54
57
  searchParameters: SearchParams,
55
58
  options: SearchOptions,
59
+ filter?: BaseFilterDto,
56
60
  ): Promise<SearchResponse<any>> {
57
61
  try {
58
- const { includeIds = [], per_page = 25 } = { ...searchParameters };
62
+ const { per_page = 25 } = { ...searchParameters };
59
63
  const includeDocuments = [];
64
+ const includeIds = filter?.includeIds || [];
60
65
 
61
66
  if (includeIds.length > 0) {
62
67
  const includeOpts = {
@@ -101,9 +106,9 @@ export abstract class ClientService<
101
106
  searchParameters.per_page = searchParameters.per_page ?? 250;
102
107
  options.cacheSearchResultsForSeconds = 1;
103
108
  const response = await this.searchDocument(searchParameters, options);
104
- const { hits = [], found = 0, page = 1 } = response;
109
+ const { hits = [], found = 0, page = 1 } = { ...response };
105
110
  let documents = hits;
106
- const hasNext = hits.length * page < found;
111
+ const hasNext = hits?.length * page < found;
107
112
  if (hasNext) {
108
113
  searchParameters.page = page + 1;
109
114
  documents = await this.getAllRawDocs(searchParameters, options);