@konplit-services/common 1.3.0 → 1.4.0

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.
@@ -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
  }
@@ -43,4 +43,5 @@ export declare const calculateDelay: (targetDate: string | Date) => {
43
43
  * @returns boolean - true if refund can still be processed from the settlement ledger
44
44
  */
45
45
  export declare function canRefundFromSettlementLedgerByDay(transactionCreatedAt: string | Date, bufferInMinutes?: number): boolean;
46
+ export declare function getSettlementDate(transactionDate?: string | Date | Date): Date;
46
47
  export {};
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.canRefundFromSettlementLedgerByDay = exports.calculateDelay = exports.getFutureDateFromPlan = exports.getDuration = exports.convertDateToUTC = exports.convertDateToUTCString = exports.convertDateToUTCRange = exports.convertDateToUTCRangeString = exports.isTodayOrFuture = exports.getStartAndEndDate = exports.getCurrentDayRange = exports.getPreviousDayRange = exports.convertToDate = exports.formatDateTime = exports.interswitchRefundDateFormat = exports.formatDate = void 0;
6
+ exports.getSettlementDate = exports.canRefundFromSettlementLedgerByDay = exports.calculateDelay = exports.getFutureDateFromPlan = exports.getDuration = exports.convertDateToUTC = exports.convertDateToUTCString = exports.convertDateToUTCRange = exports.convertDateToUTCRangeString = exports.isTodayOrFuture = exports.getStartAndEndDate = exports.getCurrentDayRange = exports.getPreviousDayRange = exports.convertToDate = exports.formatDateTime = exports.interswitchRefundDateFormat = exports.formatDate = void 0;
7
7
  const dayjs_1 = __importDefault(require("dayjs"));
8
8
  const utc_1 = __importDefault(require("dayjs/plugin/utc"));
9
9
  // Extend dayjs with the UTC plugin
@@ -191,3 +191,19 @@ function canRefundFromSettlementLedgerByDay(transactionCreatedAt, bufferInMinute
191
191
  return now.isBefore(cutoffTime);
192
192
  }
193
193
  exports.canRefundFromSettlementLedgerByDay = canRefundFromSettlementLedgerByDay;
194
+ function getSettlementDate(transactionDate = new Date()) {
195
+ const txDate = (0, dayjs_1.default)(transactionDate);
196
+ const day = txDate.day(); // 0 = Sunday, ..., 6 = Saturday
197
+ let settlementDate;
198
+ if (day >= 1 && day <= 4) {
199
+ // Monday–Thursday → next day
200
+ settlementDate = txDate.add(1, 'day');
201
+ }
202
+ else {
203
+ // Friday (5), Saturday (6), Sunday (0) → next Monday
204
+ const daysToAdd = (8 - day) % 7;
205
+ settlementDate = txDate.add(daysToAdd, 'day');
206
+ }
207
+ return settlementDate.toDate(); // Return native Date object
208
+ }
209
+ exports.getSettlementDate = getSettlementDate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konplit-services/common",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",