@react-pakistan/util-functions 1.25.48 → 1.25.50
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/api/stellar-solutions/app-user/index.d.ts +1 -1
- package/api/stellar-solutions/bank/index.d.ts +1 -1
- package/api/stellar-solutions/branch/index.d.ts +1 -1
- package/api/stellar-solutions/company/index.d.ts +1 -1
- package/api/stellar-solutions/company-report/index.d.ts +1 -1
- package/api/stellar-solutions/contact/index.d.ts +1 -1
- package/api/stellar-solutions/currency/index.d.ts +1 -1
- package/api/stellar-solutions/customer/index.d.ts +1 -1
- package/api/stellar-solutions/expense/index.d.ts +1 -1
- package/api/stellar-solutions/expense-category/index.d.ts +1 -1
- package/api/stellar-solutions/lead/index.d.ts +1 -1
- package/api/stellar-solutions/menu-order/index.d.ts +1 -1
- package/api/stellar-solutions/payment/index.d.ts +1 -1
- package/api/stellar-solutions/payment/index.js +2 -2
- package/api/stellar-solutions/payment-mode/index.d.ts +1 -1
- package/api/stellar-solutions/preference/index.d.ts +1 -1
- package/api/stellar-solutions/product/index.d.ts +1 -1
- package/api/stellar-solutions/product-category/index.d.ts +1 -1
- package/api/stellar-solutions/profile/index.d.ts +1 -1
- package/api/stellar-solutions/quote-invoice/index.d.ts +1 -1
- package/api/stellar-solutions/quote-invoice-report/index.d.ts +1 -1
- package/api/stellar-solutions/tax/index.d.ts +1 -1
- package/api/stellar-solutions/types/common.d.ts +24 -0
- package/api/stellar-solutions/types/common.js +22 -0
- package/api/stellar-solutions/{type.d.ts → types/erp.d.ts} +1 -199
- package/api/stellar-solutions/types/erp.js +68 -0
- package/api/stellar-solutions/types/index.d.ts +3 -0
- package/api/stellar-solutions/types/index.js +19 -0
- package/api/stellar-solutions/types/pos.d.ts +176 -0
- package/api/stellar-solutions/types/pos.js +61 -0
- package/general/index.d.ts +0 -1
- package/general/index.js +0 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/api/stellar-solutions/bank/cache.d.ts +0 -0
- package/api/stellar-solutions/bank/cache.js +0 -237
- package/api/stellar-solutions/branch/cache.d.ts +0 -0
- package/api/stellar-solutions/branch/cache.js +0 -241
- package/api/stellar-solutions/company/cache.d.ts +0 -0
- package/api/stellar-solutions/company/cache.js +0 -247
- package/api/stellar-solutions/contact/cache.d.ts +0 -0
- package/api/stellar-solutions/contact/cache.js +0 -247
- package/api/stellar-solutions/currency/cache.d.ts +0 -0
- package/api/stellar-solutions/currency/cache.js +0 -243
- package/api/stellar-solutions/customer/cache.d.ts +0 -0
- package/api/stellar-solutions/customer/cache.js +0 -249
- package/api/stellar-solutions/expense/cache.d.ts +0 -0
- package/api/stellar-solutions/expense/cache.js +0 -247
- package/api/stellar-solutions/expense-category/cache.d.ts +0 -0
- package/api/stellar-solutions/expense-category/cache.js +0 -224
- package/api/stellar-solutions/payment-mode/cache.d.ts +0 -0
- package/api/stellar-solutions/payment-mode/cache.js +0 -245
- package/api/stellar-solutions/preference/cache.d.ts +0 -0
- package/api/stellar-solutions/preference/cache.js +0 -218
- package/api/stellar-solutions/product/cache.d.ts +0 -0
- package/api/stellar-solutions/product/cache.js +0 -222
- package/api/stellar-solutions/product-category/cache.d.ts +0 -0
- package/api/stellar-solutions/product-category/cache.js +0 -224
- package/api/stellar-solutions/tax/cache.d.ts +0 -0
- package/api/stellar-solutions/tax/cache.js +0 -235
- package/api/stellar-solutions/type.js +0 -142
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { BaseEntity } from './common';
|
|
2
|
+
export declare enum POS_ORDER_STATUS {
|
|
3
|
+
OPEN = "OPEN",
|
|
4
|
+
CLOSED = "CLOSED",
|
|
5
|
+
CANCELLED = "CANCELLED",
|
|
6
|
+
REFUNDED = "REFUNDED"
|
|
7
|
+
}
|
|
8
|
+
export declare enum POS_PAYMENT_STATUS {
|
|
9
|
+
PENDING = "PENDING",
|
|
10
|
+
PAID = "PAID",
|
|
11
|
+
FAILED = "FAILED",
|
|
12
|
+
REFUNDED = "REFUNDED"
|
|
13
|
+
}
|
|
14
|
+
export declare enum POS_PAYMENT_METHOD_TYPE {
|
|
15
|
+
CASH = "CASH",
|
|
16
|
+
CARD = "CARD",
|
|
17
|
+
GIFT_CARD = "GIFT_CARD",
|
|
18
|
+
MOBILE_WALLET = "MOBILE_WALLET",
|
|
19
|
+
OTHER = "OTHER"
|
|
20
|
+
}
|
|
21
|
+
export declare enum POS_REGISTER_STATUS {
|
|
22
|
+
ACTIVE = "ACTIVE",
|
|
23
|
+
INACTIVE = "INACTIVE"
|
|
24
|
+
}
|
|
25
|
+
export declare enum POS_TAX_TYPE {
|
|
26
|
+
EXCLUSIVE = "EXCLUSIVE",
|
|
27
|
+
INCLUSIVE = "INCLUSIVE"
|
|
28
|
+
}
|
|
29
|
+
export declare enum POS_TABLE_STATUS {
|
|
30
|
+
AVAILABLE = "AVAILABLE",
|
|
31
|
+
OCCUPIED = "OCCUPIED",
|
|
32
|
+
RESERVED = "RESERVED"
|
|
33
|
+
}
|
|
34
|
+
export declare enum POS_RESERVATION_STATUS {
|
|
35
|
+
PENDING = "PENDING",
|
|
36
|
+
CONFIRMED = "CONFIRMED",
|
|
37
|
+
CANCELLED = "CANCELLED",
|
|
38
|
+
COMPLETED = "COMPLETED"
|
|
39
|
+
}
|
|
40
|
+
export declare enum POS_SHIFT_STATUS {
|
|
41
|
+
OPEN = "OPEN",
|
|
42
|
+
CLOSED = "CLOSED"
|
|
43
|
+
}
|
|
44
|
+
export declare enum POS_DISCOUNT_TYPE {
|
|
45
|
+
FIXED = "FIXED",
|
|
46
|
+
PERCENTAGE = "PERCENTAGE"
|
|
47
|
+
}
|
|
48
|
+
export interface POSStoreBE extends BaseEntity {
|
|
49
|
+
name: string;
|
|
50
|
+
code?: string;
|
|
51
|
+
address?: string;
|
|
52
|
+
phone?: string;
|
|
53
|
+
email?: string;
|
|
54
|
+
currency: string;
|
|
55
|
+
meta?: any;
|
|
56
|
+
enabled: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface POSRegisterBE extends BaseEntity {
|
|
59
|
+
name: string;
|
|
60
|
+
storeId: string;
|
|
61
|
+
status: POS_REGISTER_STATUS;
|
|
62
|
+
meta?: any;
|
|
63
|
+
}
|
|
64
|
+
export interface POSShiftBE extends BaseEntity {
|
|
65
|
+
registerId: string;
|
|
66
|
+
openedByUserId?: string;
|
|
67
|
+
openedAt: Date;
|
|
68
|
+
closedAt?: Date;
|
|
69
|
+
openingAmount: number;
|
|
70
|
+
closingAmount?: number;
|
|
71
|
+
status: POS_SHIFT_STATUS;
|
|
72
|
+
meta?: any;
|
|
73
|
+
}
|
|
74
|
+
export interface POSCategoryBE extends BaseEntity {
|
|
75
|
+
name: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
storeId: string;
|
|
78
|
+
parentId?: string;
|
|
79
|
+
meta?: any;
|
|
80
|
+
}
|
|
81
|
+
export interface POSProductBE extends BaseEntity {
|
|
82
|
+
sku?: string;
|
|
83
|
+
name: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
price: number;
|
|
86
|
+
cost?: number;
|
|
87
|
+
stock: number;
|
|
88
|
+
storeId: string;
|
|
89
|
+
categoryId?: string;
|
|
90
|
+
meta?: any;
|
|
91
|
+
}
|
|
92
|
+
export interface POSProductVariantBE extends BaseEntity {
|
|
93
|
+
productId: string;
|
|
94
|
+
name: string;
|
|
95
|
+
sku?: string;
|
|
96
|
+
price: number;
|
|
97
|
+
stock: number;
|
|
98
|
+
meta?: any;
|
|
99
|
+
}
|
|
100
|
+
export interface POSCustomerBE extends BaseEntity {
|
|
101
|
+
name: string;
|
|
102
|
+
email?: string;
|
|
103
|
+
phone?: string;
|
|
104
|
+
storeId: string;
|
|
105
|
+
loyaltyPoints: number;
|
|
106
|
+
meta?: any;
|
|
107
|
+
}
|
|
108
|
+
export interface POSTableBE extends BaseEntity {
|
|
109
|
+
storeId: string;
|
|
110
|
+
name: string;
|
|
111
|
+
seats: number;
|
|
112
|
+
status: POS_TABLE_STATUS;
|
|
113
|
+
meta?: any;
|
|
114
|
+
}
|
|
115
|
+
export interface POSReservationBE extends BaseEntity {
|
|
116
|
+
tableId: string;
|
|
117
|
+
customerId: string;
|
|
118
|
+
startAt: Date;
|
|
119
|
+
endAt: Date;
|
|
120
|
+
partySize: number;
|
|
121
|
+
status: POS_RESERVATION_STATUS;
|
|
122
|
+
meta?: any;
|
|
123
|
+
}
|
|
124
|
+
export interface POSOrderBE extends BaseEntity {
|
|
125
|
+
orderNumber: string;
|
|
126
|
+
storeId: string;
|
|
127
|
+
registerId?: string;
|
|
128
|
+
customerId?: string;
|
|
129
|
+
tableId?: string;
|
|
130
|
+
status: POS_ORDER_STATUS;
|
|
131
|
+
paymentStatus: POS_PAYMENT_STATUS;
|
|
132
|
+
subTotal: number;
|
|
133
|
+
taxTotal: number;
|
|
134
|
+
discountTotal: number;
|
|
135
|
+
serviceCharge: number;
|
|
136
|
+
total: number;
|
|
137
|
+
note?: string;
|
|
138
|
+
meta?: any;
|
|
139
|
+
}
|
|
140
|
+
export interface POSOrderItemBE extends BaseEntity {
|
|
141
|
+
orderId: string;
|
|
142
|
+
productId?: string;
|
|
143
|
+
variantId?: string;
|
|
144
|
+
name: string;
|
|
145
|
+
quantity: number;
|
|
146
|
+
unitPrice: number;
|
|
147
|
+
total: number;
|
|
148
|
+
taxAmount: number;
|
|
149
|
+
discountAmount: number;
|
|
150
|
+
meta?: any;
|
|
151
|
+
}
|
|
152
|
+
export interface POSPaymentBE extends BaseEntity {
|
|
153
|
+
orderId: string;
|
|
154
|
+
amount: number;
|
|
155
|
+
method: POS_PAYMENT_METHOD_TYPE;
|
|
156
|
+
methodLabel?: string;
|
|
157
|
+
status: POS_PAYMENT_STATUS;
|
|
158
|
+
transactionRef?: string;
|
|
159
|
+
processedAt?: Date;
|
|
160
|
+
meta?: any;
|
|
161
|
+
}
|
|
162
|
+
export interface POSTaxBE extends BaseEntity {
|
|
163
|
+
name: string;
|
|
164
|
+
rate: number;
|
|
165
|
+
type: POS_TAX_TYPE;
|
|
166
|
+
isDefault: boolean;
|
|
167
|
+
storeId: string;
|
|
168
|
+
meta?: any;
|
|
169
|
+
}
|
|
170
|
+
export interface POSDiscountBE extends BaseEntity {
|
|
171
|
+
name: string;
|
|
172
|
+
type: POS_DISCOUNT_TYPE;
|
|
173
|
+
value: number;
|
|
174
|
+
storeId: string;
|
|
175
|
+
meta?: any;
|
|
176
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POS_DISCOUNT_TYPE = exports.POS_SHIFT_STATUS = exports.POS_RESERVATION_STATUS = exports.POS_TABLE_STATUS = exports.POS_TAX_TYPE = exports.POS_REGISTER_STATUS = exports.POS_PAYMENT_METHOD_TYPE = exports.POS_PAYMENT_STATUS = exports.POS_ORDER_STATUS = void 0;
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// POS ENUMS
|
|
6
|
+
// ============================================================================
|
|
7
|
+
var POS_ORDER_STATUS;
|
|
8
|
+
(function (POS_ORDER_STATUS) {
|
|
9
|
+
POS_ORDER_STATUS["OPEN"] = "OPEN";
|
|
10
|
+
POS_ORDER_STATUS["CLOSED"] = "CLOSED";
|
|
11
|
+
POS_ORDER_STATUS["CANCELLED"] = "CANCELLED";
|
|
12
|
+
POS_ORDER_STATUS["REFUNDED"] = "REFUNDED";
|
|
13
|
+
})(POS_ORDER_STATUS || (exports.POS_ORDER_STATUS = POS_ORDER_STATUS = {}));
|
|
14
|
+
var POS_PAYMENT_STATUS;
|
|
15
|
+
(function (POS_PAYMENT_STATUS) {
|
|
16
|
+
POS_PAYMENT_STATUS["PENDING"] = "PENDING";
|
|
17
|
+
POS_PAYMENT_STATUS["PAID"] = "PAID";
|
|
18
|
+
POS_PAYMENT_STATUS["FAILED"] = "FAILED";
|
|
19
|
+
POS_PAYMENT_STATUS["REFUNDED"] = "REFUNDED";
|
|
20
|
+
})(POS_PAYMENT_STATUS || (exports.POS_PAYMENT_STATUS = POS_PAYMENT_STATUS = {}));
|
|
21
|
+
var POS_PAYMENT_METHOD_TYPE;
|
|
22
|
+
(function (POS_PAYMENT_METHOD_TYPE) {
|
|
23
|
+
POS_PAYMENT_METHOD_TYPE["CASH"] = "CASH";
|
|
24
|
+
POS_PAYMENT_METHOD_TYPE["CARD"] = "CARD";
|
|
25
|
+
POS_PAYMENT_METHOD_TYPE["GIFT_CARD"] = "GIFT_CARD";
|
|
26
|
+
POS_PAYMENT_METHOD_TYPE["MOBILE_WALLET"] = "MOBILE_WALLET";
|
|
27
|
+
POS_PAYMENT_METHOD_TYPE["OTHER"] = "OTHER";
|
|
28
|
+
})(POS_PAYMENT_METHOD_TYPE || (exports.POS_PAYMENT_METHOD_TYPE = POS_PAYMENT_METHOD_TYPE = {}));
|
|
29
|
+
var POS_REGISTER_STATUS;
|
|
30
|
+
(function (POS_REGISTER_STATUS) {
|
|
31
|
+
POS_REGISTER_STATUS["ACTIVE"] = "ACTIVE";
|
|
32
|
+
POS_REGISTER_STATUS["INACTIVE"] = "INACTIVE";
|
|
33
|
+
})(POS_REGISTER_STATUS || (exports.POS_REGISTER_STATUS = POS_REGISTER_STATUS = {}));
|
|
34
|
+
var POS_TAX_TYPE;
|
|
35
|
+
(function (POS_TAX_TYPE) {
|
|
36
|
+
POS_TAX_TYPE["EXCLUSIVE"] = "EXCLUSIVE";
|
|
37
|
+
POS_TAX_TYPE["INCLUSIVE"] = "INCLUSIVE";
|
|
38
|
+
})(POS_TAX_TYPE || (exports.POS_TAX_TYPE = POS_TAX_TYPE = {}));
|
|
39
|
+
var POS_TABLE_STATUS;
|
|
40
|
+
(function (POS_TABLE_STATUS) {
|
|
41
|
+
POS_TABLE_STATUS["AVAILABLE"] = "AVAILABLE";
|
|
42
|
+
POS_TABLE_STATUS["OCCUPIED"] = "OCCUPIED";
|
|
43
|
+
POS_TABLE_STATUS["RESERVED"] = "RESERVED";
|
|
44
|
+
})(POS_TABLE_STATUS || (exports.POS_TABLE_STATUS = POS_TABLE_STATUS = {}));
|
|
45
|
+
var POS_RESERVATION_STATUS;
|
|
46
|
+
(function (POS_RESERVATION_STATUS) {
|
|
47
|
+
POS_RESERVATION_STATUS["PENDING"] = "PENDING";
|
|
48
|
+
POS_RESERVATION_STATUS["CONFIRMED"] = "CONFIRMED";
|
|
49
|
+
POS_RESERVATION_STATUS["CANCELLED"] = "CANCELLED";
|
|
50
|
+
POS_RESERVATION_STATUS["COMPLETED"] = "COMPLETED";
|
|
51
|
+
})(POS_RESERVATION_STATUS || (exports.POS_RESERVATION_STATUS = POS_RESERVATION_STATUS = {}));
|
|
52
|
+
var POS_SHIFT_STATUS;
|
|
53
|
+
(function (POS_SHIFT_STATUS) {
|
|
54
|
+
POS_SHIFT_STATUS["OPEN"] = "OPEN";
|
|
55
|
+
POS_SHIFT_STATUS["CLOSED"] = "CLOSED";
|
|
56
|
+
})(POS_SHIFT_STATUS || (exports.POS_SHIFT_STATUS = POS_SHIFT_STATUS = {}));
|
|
57
|
+
var POS_DISCOUNT_TYPE;
|
|
58
|
+
(function (POS_DISCOUNT_TYPE) {
|
|
59
|
+
POS_DISCOUNT_TYPE["FIXED"] = "FIXED";
|
|
60
|
+
POS_DISCOUNT_TYPE["PERCENTAGE"] = "PERCENTAGE";
|
|
61
|
+
})(POS_DISCOUNT_TYPE || (exports.POS_DISCOUNT_TYPE = POS_DISCOUNT_TYPE = {}));
|
package/general/index.d.ts
CHANGED
|
@@ -66,7 +66,6 @@ export * from './get-href';
|
|
|
66
66
|
export * from './get-month-name';
|
|
67
67
|
export * from './get-month-number';
|
|
68
68
|
export * from './get-pathname';
|
|
69
|
-
export * from './get-week-day';
|
|
70
69
|
export * from './image-url-to-base64';
|
|
71
70
|
export * from './is-created-or-updated';
|
|
72
71
|
export * from './is-next-button-disabled';
|
package/general/index.js
CHANGED
|
@@ -82,7 +82,6 @@ __exportStar(require("./get-href"), exports);
|
|
|
82
82
|
__exportStar(require("./get-month-name"), exports);
|
|
83
83
|
__exportStar(require("./get-month-number"), exports);
|
|
84
84
|
__exportStar(require("./get-pathname"), exports);
|
|
85
|
-
__exportStar(require("./get-week-day"), exports);
|
|
86
85
|
__exportStar(require("./image-url-to-base64"), exports);
|
|
87
86
|
__exportStar(require("./is-created-or-updated"), exports);
|
|
88
87
|
__exportStar(require("./is-next-button-disabled"), exports);
|
package/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export * from './api/stellar-solutions/profile';
|
|
|
21
21
|
export * from './api/stellar-solutions/quote-invoice-report';
|
|
22
22
|
export * from './api/stellar-solutions/quote-invoice';
|
|
23
23
|
export * from './api/stellar-solutions/tax';
|
|
24
|
-
export * from './api/stellar-solutions/
|
|
24
|
+
export * from './api/stellar-solutions/types';
|
|
25
25
|
export * from './constants';
|
|
26
26
|
export * from './general';
|
|
27
27
|
export * from './hooks';
|
package/index.js
CHANGED
|
@@ -37,7 +37,7 @@ __exportStar(require("./api/stellar-solutions/profile"), exports);
|
|
|
37
37
|
__exportStar(require("./api/stellar-solutions/quote-invoice-report"), exports);
|
|
38
38
|
__exportStar(require("./api/stellar-solutions/quote-invoice"), exports);
|
|
39
39
|
__exportStar(require("./api/stellar-solutions/tax"), exports);
|
|
40
|
-
__exportStar(require("./api/stellar-solutions/
|
|
40
|
+
__exportStar(require("./api/stellar-solutions/types"), exports);
|
|
41
41
|
__exportStar(require("./constants"), exports);
|
|
42
42
|
__exportStar(require("./general"), exports);
|
|
43
43
|
__exportStar(require("./hooks"), exports);
|
package/package.json
CHANGED
|
File without changes
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
// import { API_ROUTES } from '../constants';
|
|
2
|
-
// import { BankBE, LS_KEYS } from '../type';
|
|
3
|
-
// import { API_METHODS } from '../../../constants/api-methods';
|
|
4
|
-
// import { fetchData } from '../../../general/fetch-data';
|
|
5
|
-
// import { getStorageValue } from '../../../local-storage/get-storage-value';
|
|
6
|
-
// import { setStorageValue } from '../../../local-storage/set-storage-value';
|
|
7
|
-
// import { ONE_WEEK_IN_MS } from '../../../constants';
|
|
8
|
-
// interface CachedBanks {
|
|
9
|
-
// banks: BankBE[];
|
|
10
|
-
// cachedAt: string;
|
|
11
|
-
// }
|
|
12
|
-
// /**
|
|
13
|
-
// * Synchronous utility function to get banks from cache only
|
|
14
|
-
// * Returns cached data immediately if available and fresh, otherwise returns empty array
|
|
15
|
-
// * Does not trigger any API calls
|
|
16
|
-
// *
|
|
17
|
-
// * @returns BankBE[] - Array of cached banks or empty array wrapper ({count, items})
|
|
18
|
-
// *
|
|
19
|
-
// * @example
|
|
20
|
-
// * const banks = getCachedBanksSync();
|
|
21
|
-
// * if (banks.items.length > 0) {
|
|
22
|
-
// * console.log(banks.items[0].bankName);
|
|
23
|
-
// * }
|
|
24
|
-
// */
|
|
25
|
-
// export const getCachedBanksSync = (): {
|
|
26
|
-
// count: number;
|
|
27
|
-
// items: BankBE[];
|
|
28
|
-
// } => {
|
|
29
|
-
// try {
|
|
30
|
-
// const cachedData = getStorageValue(LS_KEYS.BANKS) as CachedBanks | null;
|
|
31
|
-
// if (!cachedData) {
|
|
32
|
-
// return { count: 0, items: [] };
|
|
33
|
-
// }
|
|
34
|
-
// const currentTime = new Date().getTime();
|
|
35
|
-
// const cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
36
|
-
// const ageInMs = currentTime - cachedTime;
|
|
37
|
-
// // If cached data is less than 1 week old, return it
|
|
38
|
-
// if (ageInMs < ONE_WEEK_IN_MS) {
|
|
39
|
-
// return {
|
|
40
|
-
// count: cachedData.banks.length,
|
|
41
|
-
// items: cachedData.banks,
|
|
42
|
-
// };
|
|
43
|
-
// }
|
|
44
|
-
// return { count: 0, items: [] };
|
|
45
|
-
// } catch (error) {
|
|
46
|
-
// console.error('Error getting cached banks:', error);
|
|
47
|
-
// return { count: 0, items: [] };
|
|
48
|
-
// }
|
|
49
|
-
// };
|
|
50
|
-
// /**
|
|
51
|
-
// * Utility function to get banks from cache or fetch from API
|
|
52
|
-
// *
|
|
53
|
-
// * This function manages a localStorage cache of banks with the following logic:
|
|
54
|
-
// * - If banks exist in cache and are less than 1 week old, return cached version
|
|
55
|
-
// * - If banks exist but are older than 1 week, fetch fresh data and update cache
|
|
56
|
-
// * - If banks don't exist in cache, fetch from API and cache them
|
|
57
|
-
// *
|
|
58
|
-
// * @param searchQuery - Optional search query to filter banks
|
|
59
|
-
// * @param pageLimit - Number of banks to fetch (default: 100)
|
|
60
|
-
// * @returns Promise<{count:number, items: BankBE[]}> - Paged banks
|
|
61
|
-
// *
|
|
62
|
-
// * @example
|
|
63
|
-
// * const banks = await getCachedBanks();
|
|
64
|
-
// * console.log(banks.items[0].bankName);
|
|
65
|
-
// *
|
|
66
|
-
// * // With search
|
|
67
|
-
// * const filtered = await getCachedBanks('Chase');
|
|
68
|
-
// */
|
|
69
|
-
// export const getCachedBanks = async (
|
|
70
|
-
// searchQuery?: string,
|
|
71
|
-
// pageLimit: number = 100
|
|
72
|
-
// ): Promise<{
|
|
73
|
-
// count: number;
|
|
74
|
-
// items: BankBE[];
|
|
75
|
-
// }> => {
|
|
76
|
-
// try {
|
|
77
|
-
// // If there's a search query, always fetch fresh data (don't use cache)
|
|
78
|
-
// if (searchQuery && searchQuery.trim()) {
|
|
79
|
-
// const response = await fetchData({
|
|
80
|
-
// url: API_ROUTES.BANKS,
|
|
81
|
-
// body: JSON.stringify({
|
|
82
|
-
// searchQuery,
|
|
83
|
-
// pageLimit,
|
|
84
|
-
// currentPage: 1,
|
|
85
|
-
// }),
|
|
86
|
-
// method: API_METHODS.POST,
|
|
87
|
-
// });
|
|
88
|
-
// return response?.data || { count: 0, items: [] };
|
|
89
|
-
// }
|
|
90
|
-
// // Get the cached data from localStorage
|
|
91
|
-
// const cachedData = getStorageValue(LS_KEYS.BANKS) as CachedBanks | null;
|
|
92
|
-
// const currentTime = new Date().getTime();
|
|
93
|
-
// // Check if cached data exists and is still fresh
|
|
94
|
-
// if (cachedData) {
|
|
95
|
-
// const cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
96
|
-
// const ageInMs = currentTime - cachedTime;
|
|
97
|
-
// // If cached data is less than 1 week old, return it
|
|
98
|
-
// if (ageInMs < ONE_WEEK_IN_MS) {
|
|
99
|
-
// return {
|
|
100
|
-
// count: cachedData.banks.length,
|
|
101
|
-
// items: cachedData.banks,
|
|
102
|
-
// };
|
|
103
|
-
// }
|
|
104
|
-
// }
|
|
105
|
-
// // If no cached data or data is older than 1 week, fetch fresh data
|
|
106
|
-
// const response = await fetchData({
|
|
107
|
-
// url: API_ROUTES.BANKS,
|
|
108
|
-
// body: JSON.stringify({
|
|
109
|
-
// pageLimit,
|
|
110
|
-
// currentPage: 1,
|
|
111
|
-
// }),
|
|
112
|
-
// method: API_METHODS.POST,
|
|
113
|
-
// });
|
|
114
|
-
// if (response?.data?.items) {
|
|
115
|
-
// // Update the cache with fresh data
|
|
116
|
-
// const updatedCache: CachedBanks = {
|
|
117
|
-
// banks: response.data.items,
|
|
118
|
-
// cachedAt: new Date().toISOString(),
|
|
119
|
-
// };
|
|
120
|
-
// setStorageValue(LS_KEYS.BANKS, updatedCache);
|
|
121
|
-
// return response.data;
|
|
122
|
-
// }
|
|
123
|
-
// return { count: 0, items: [] };
|
|
124
|
-
// } catch (error) {
|
|
125
|
-
// console.error('Error fetching banks:', error);
|
|
126
|
-
// return { count: 0, items: [] };
|
|
127
|
-
// }
|
|
128
|
-
// };
|
|
129
|
-
// /**
|
|
130
|
-
// * Utility function to get a specific bank by ID from cache
|
|
131
|
-
// * If not found in cache, returns null (does not trigger API call)
|
|
132
|
-
// *
|
|
133
|
-
// * @param bankId - The ID of the bank to retrieve
|
|
134
|
-
// * @returns BankBE | null - The bank or null if not found
|
|
135
|
-
// *
|
|
136
|
-
// * @example
|
|
137
|
-
// * const bank = getCachedBankById('bank-123');
|
|
138
|
-
// * if (bank) {
|
|
139
|
-
// * console.log(bank.bankName);
|
|
140
|
-
// * }
|
|
141
|
-
// */
|
|
142
|
-
// export const getCachedBankById = (bankId: string): BankBE | null => {
|
|
143
|
-
// if (!bankId) {
|
|
144
|
-
// return null;
|
|
145
|
-
// }
|
|
146
|
-
// try {
|
|
147
|
-
// const banks = getCachedBanksSync().items;
|
|
148
|
-
// return banks.find((bank) => bank.id === bankId) || null;
|
|
149
|
-
// } catch (error) {
|
|
150
|
-
// console.error('Error getting cached bank by ID:', error);
|
|
151
|
-
// return null;
|
|
152
|
-
// }
|
|
153
|
-
// };
|
|
154
|
-
// /**
|
|
155
|
-
// * Utility function to get a specific bank by account number from cache
|
|
156
|
-
// * If not found in cache, returns null (does not trigger API call)
|
|
157
|
-
// *
|
|
158
|
-
// * @param accountNumber - The account number of the bank to retrieve
|
|
159
|
-
// * @returns BankBE | null - The bank or null if not found
|
|
160
|
-
// *
|
|
161
|
-
// * @example
|
|
162
|
-
// * const bank = getCachedBankByAccountNumber('1234567890');
|
|
163
|
-
// * if (bank) {
|
|
164
|
-
// * console.log(bank.bankName);
|
|
165
|
-
// * }
|
|
166
|
-
// */
|
|
167
|
-
// export const getCachedBankByAccountNumber = (
|
|
168
|
-
// accountNumber: string
|
|
169
|
-
// ): BankBE | null => {
|
|
170
|
-
// if (!accountNumber) {
|
|
171
|
-
// return null;
|
|
172
|
-
// }
|
|
173
|
-
// try {
|
|
174
|
-
// const banks = getCachedBanksSync().items;
|
|
175
|
-
// return banks.find((bank) => bank.accountNumber === accountNumber) || null;
|
|
176
|
-
// } catch (error) {
|
|
177
|
-
// console.error('Error getting cached bank by account number:', error);
|
|
178
|
-
// return null;
|
|
179
|
-
// }
|
|
180
|
-
// };
|
|
181
|
-
// /**
|
|
182
|
-
// * Utility function to invalidate (remove) banks from cache
|
|
183
|
-
// * Useful when banks have been updated and you want to force a refresh
|
|
184
|
-
// *
|
|
185
|
-
// * @example
|
|
186
|
-
// * invalidateBanksCache();
|
|
187
|
-
// * const freshBanks = await getCachedBanks();
|
|
188
|
-
// */
|
|
189
|
-
// export const invalidateBanksCache = (): void => {
|
|
190
|
-
// try {
|
|
191
|
-
// localStorage.removeItem(LS_KEYS.BANKS);
|
|
192
|
-
// } catch (error) {
|
|
193
|
-
// console.error('Error invalidating banks cache:', error);
|
|
194
|
-
// }
|
|
195
|
-
// };
|
|
196
|
-
// /**
|
|
197
|
-
// * Utility function to preload banks into cache
|
|
198
|
-
// * Useful to call on app initialization or login
|
|
199
|
-
// *
|
|
200
|
-
// * @returns Promise<{count:number, items: BankBE[]}> - Array of preloaded banks
|
|
201
|
-
// *
|
|
202
|
-
// * @example
|
|
203
|
-
// * // On app initialization
|
|
204
|
-
// * await preloadBanks();
|
|
205
|
-
// */
|
|
206
|
-
// export const preloadBanks = async (): Promise<{
|
|
207
|
-
// count: number;
|
|
208
|
-
// items: BankBE[];
|
|
209
|
-
// }> => {
|
|
210
|
-
// return getCachedBanks();
|
|
211
|
-
// };
|
|
212
|
-
// /**
|
|
213
|
-
// * Utility function to check if banks cache is stale
|
|
214
|
-
// * Returns true if cache is older than 1 week or doesn't exist
|
|
215
|
-
// *
|
|
216
|
-
// * @returns boolean - True if cache is stale or doesn't exist
|
|
217
|
-
// *
|
|
218
|
-
// * @example
|
|
219
|
-
// * if (isBanksCacheStale()) {
|
|
220
|
-
// * await getCachedBanks(); // This will fetch fresh data
|
|
221
|
-
// * }
|
|
222
|
-
// */
|
|
223
|
-
// export const isBanksCacheStale = (): boolean => {
|
|
224
|
-
// try {
|
|
225
|
-
// const cachedData = getStorageValue(LS_KEYS.BANKS) as CachedBanks | null;
|
|
226
|
-
// if (!cachedData) {
|
|
227
|
-
// return true;
|
|
228
|
-
// }
|
|
229
|
-
// const currentTime = new Date().getTime();
|
|
230
|
-
// const cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
231
|
-
// const ageInMs = currentTime - cachedTime;
|
|
232
|
-
// return ageInMs >= ONE_WEEK_IN_MS;
|
|
233
|
-
// } catch (error) {
|
|
234
|
-
// console.error('Error checking banks cache staleness:', error);
|
|
235
|
-
// return true;
|
|
236
|
-
// }
|
|
237
|
-
// };
|
|
File without changes
|