@konplit-services/common 1.3.1 → 1.4.1

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.
@@ -6,6 +6,7 @@ export interface RecipientFileUploadCreatedEvent {
6
6
  streamEvents: StreamEvent.Event;
7
7
  data: {
8
8
  merchantId: string;
9
+ accountId: string;
9
10
  filePath: string;
10
11
  fileName: string;
11
12
  usage: Usage;
@@ -29,6 +29,7 @@ export interface FilterOptions {
29
29
  order?: "asc" | "desc";
30
30
  merchantId?: string;
31
31
  accountId?: string;
32
+ dateField?: string;
32
33
  [key: string]: any;
33
34
  }
34
35
  export declare const generateQueryObject: (filters: FilterOptions, searchesFieldNames?: string[], select?: string | Record<string, any>, populate?: (string | PopulateOptions)[]) => {
@@ -55,7 +55,7 @@ function paginate(model, options = {}) {
55
55
  }
56
56
  exports.paginate = paginate;
57
57
  const generateQueryObject = (filters, searchesFieldNames = [], select = "", populate = []) => {
58
- const { status, limit, page, sort_by = "createdAt", order = "desc", merchantId, accountId, } = filters;
58
+ const { status, limit, page, sort_by = "createdAt", order = "desc", merchantId, accountId, dateField, } = filters;
59
59
  const excludes = [
60
60
  "status",
61
61
  "from",
@@ -67,6 +67,7 @@ const generateQueryObject = (filters, searchesFieldNames = [], select = "", popu
67
67
  "accountId",
68
68
  "merchantId",
69
69
  "order",
70
+ "dateField"
70
71
  ];
71
72
  const query = {};
72
73
  let sort = {};
@@ -95,15 +96,17 @@ const generateQueryObject = (filters, searchesFieldNames = [], select = "", popu
95
96
  if (filters.status) {
96
97
  query.status = status;
97
98
  }
99
+ // for dynamic date creation
100
+ const fieldToFilter = dateField || "createdAt";
98
101
  if (filters.from && filters.to) {
99
102
  const date = (0, date_processing_1.convertDateToUTCRange)(filters.from, filters.to);
100
- query.createdAt = {
103
+ query[fieldToFilter] = {
101
104
  $gte: date.startUTC,
102
105
  $lte: date.endUTC,
103
106
  };
104
107
  }
105
108
  else if (filters.from) {
106
- query.createdAt = {
109
+ query[fieldToFilter] = {
107
110
  $gte: (0, date_processing_1.convertDateToUTC)(filters.from),
108
111
  };
109
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konplit-services/common",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",