@react-pakistan/util-functions 1.24.99 → 1.25.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.
- package/api/stellar-solutions/app-user/index.d.ts +9 -9
- package/api/stellar-solutions/app-user/index.js +4 -4
- package/api/stellar-solutions/bank/cache.d.ts +99 -0
- package/api/stellar-solutions/bank/cache.js +256 -0
- package/api/stellar-solutions/bank/index.d.ts +10 -10
- package/api/stellar-solutions/bank/index.js +19 -4
- package/api/stellar-solutions/branch/cache.d.ts +97 -0
- package/api/stellar-solutions/branch/cache.js +256 -0
- package/api/stellar-solutions/branch/index.d.ts +10 -10
- package/api/stellar-solutions/branch/index.js +19 -4
- package/api/stellar-solutions/company/cache.d.ts +106 -0
- package/api/stellar-solutions/company/cache.js +307 -0
- package/api/stellar-solutions/company/index.d.ts +10 -10
- package/api/stellar-solutions/company/index.js +19 -4
- package/api/stellar-solutions/company-report/index.d.ts +3 -3
- package/api/stellar-solutions/company-report/index.js +1 -1
- package/api/stellar-solutions/constants.d.ts +12 -0
- package/api/stellar-solutions/constants.js +13 -1
- package/api/stellar-solutions/contact/cache.d.ts +108 -0
- package/api/stellar-solutions/contact/cache.js +307 -0
- package/api/stellar-solutions/contact/index.d.ts +10 -10
- package/api/stellar-solutions/contact/index.js +19 -4
- package/api/stellar-solutions/currency/cache.d.ts +99 -0
- package/api/stellar-solutions/currency/cache.js +256 -0
- package/api/stellar-solutions/currency/index.d.ts +10 -10
- package/api/stellar-solutions/currency/index.js +19 -4
- package/api/stellar-solutions/customer/cache.d.ts +108 -0
- package/api/stellar-solutions/customer/cache.js +307 -0
- package/api/stellar-solutions/customer/index.d.ts +12 -12
- package/api/stellar-solutions/customer/index.js +20 -5
- package/api/stellar-solutions/expense/cache.d.ts +106 -0
- package/api/stellar-solutions/expense/cache.js +307 -0
- package/api/stellar-solutions/expense/index.d.ts +10 -10
- package/api/stellar-solutions/expense/index.js +19 -4
- package/api/stellar-solutions/expense-category/cache.d.ts +94 -0
- package/api/stellar-solutions/expense-category/cache.js +280 -0
- package/api/stellar-solutions/expense-category/index.d.ts +10 -10
- package/api/stellar-solutions/expense-category/index.js +19 -4
- package/api/stellar-solutions/lead/index.d.ts +9 -9
- package/api/stellar-solutions/lead/index.js +4 -4
- package/api/stellar-solutions/menu-order/index.d.ts +9 -9
- package/api/stellar-solutions/menu-order/index.js +4 -4
- package/api/stellar-solutions/payment/index.d.ts +9 -9
- package/api/stellar-solutions/payment/index.js +4 -4
- package/api/stellar-solutions/payment-mode/cache.d.ts +97 -0
- package/api/stellar-solutions/payment-mode/cache.js +256 -0
- package/api/stellar-solutions/payment-mode/index.d.ts +10 -10
- package/api/stellar-solutions/payment-mode/index.js +19 -4
- package/api/stellar-solutions/preference/cache.d.ts +85 -0
- package/api/stellar-solutions/preference/cache.js +229 -0
- package/api/stellar-solutions/preference/index.d.ts +6 -6
- package/api/stellar-solutions/preference/index.js +17 -2
- package/api/stellar-solutions/product/cache.d.ts +9 -9
- package/api/stellar-solutions/product/cache.js +4 -4
- package/api/stellar-solutions/product/index.d.ts +10 -10
- package/api/stellar-solutions/product/index.js +6 -6
- package/api/stellar-solutions/product-category/cache.d.ts +9 -9
- package/api/stellar-solutions/product-category/cache.js +4 -4
- package/api/stellar-solutions/product-category/index.d.ts +9 -9
- package/api/stellar-solutions/product-category/index.js +4 -4
- package/api/stellar-solutions/profile/index.d.ts +13 -13
- package/api/stellar-solutions/profile/index.js +6 -6
- package/api/stellar-solutions/quote-invoice/index.d.ts +9 -9
- package/api/stellar-solutions/quote-invoice/index.js +4 -4
- package/api/stellar-solutions/quote-invoice-report/index.d.ts +3 -3
- package/api/stellar-solutions/quote-invoice-report/index.js +1 -1
- package/api/stellar-solutions/tax/cache.d.ts +97 -0
- package/api/stellar-solutions/tax/cache.js +256 -0
- package/api/stellar-solutions/tax/index.d.ts +10 -10
- package/api/stellar-solutions/tax/index.js +19 -4
- package/api/stellar-solutions/type.d.ts +57 -46
- package/api/stellar-solutions/type.js +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.isCustomersCacheStale = exports.preloadCustomers = exports.invalidateCustomersCache = exports.getCachedCustomerByPhone = exports.getCachedCustomerById = exports.getCachedCustomers = exports.getCachedCustomersSync = void 0;
|
|
60
|
+
var constants_1 = require("../constants");
|
|
61
|
+
var type_1 = require("../type");
|
|
62
|
+
var api_methods_1 = require("../../../constants/api-methods");
|
|
63
|
+
var fetch_data_1 = require("../../../general/fetch-data");
|
|
64
|
+
var get_storage_value_1 = require("../../../local-storage/get-storage-value");
|
|
65
|
+
var set_storage_value_1 = require("../../../local-storage/set-storage-value");
|
|
66
|
+
/**
|
|
67
|
+
* Synchronous utility function to get customers from cache only
|
|
68
|
+
* Returns cached data immediately if available and fresh, otherwise returns empty array
|
|
69
|
+
* Does not trigger any API calls
|
|
70
|
+
*
|
|
71
|
+
* @returns CustomerBE[] - Array of cached customers or empty array wrapper ({count, items})
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const customers = getCachedCustomersSync();
|
|
75
|
+
* if (customers.items.length > 0) {
|
|
76
|
+
* console.log(customers.items[0].firstName);
|
|
77
|
+
* }
|
|
78
|
+
*/
|
|
79
|
+
var getCachedCustomersSync = function () {
|
|
80
|
+
try {
|
|
81
|
+
var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.CUSTOMERS);
|
|
82
|
+
if (!cachedData) {
|
|
83
|
+
return { count: 0, items: [] };
|
|
84
|
+
}
|
|
85
|
+
var currentTime = new Date().getTime();
|
|
86
|
+
var cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
87
|
+
var ageInMs = currentTime - cachedTime;
|
|
88
|
+
// If cached data is less than 1 day old, return it
|
|
89
|
+
if (ageInMs < constants_1.ONE_DAY_IN_MS) {
|
|
90
|
+
return {
|
|
91
|
+
count: cachedData.customers.length,
|
|
92
|
+
items: cachedData.customers,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return { count: 0, items: [] };
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error('Error getting cached customers:', error);
|
|
99
|
+
return { count: 0, items: [] };
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.getCachedCustomersSync = getCachedCustomersSync;
|
|
103
|
+
/**
|
|
104
|
+
* Utility function to get customers from cache or fetch from API
|
|
105
|
+
*
|
|
106
|
+
* This function manages a localStorage cache of customers with the following logic:
|
|
107
|
+
* - If customers exist in cache and are less than 1 day old, return cached version
|
|
108
|
+
* - If customers exist but are older than 1 day, fetch fresh data and update cache
|
|
109
|
+
* - If customers don't exist in cache, fetch from API and cache them
|
|
110
|
+
*
|
|
111
|
+
* @param searchQuery - Optional search query to filter customers
|
|
112
|
+
* @param filters - Optional filters object to apply additional filtering (bypasses cache)
|
|
113
|
+
* @param pageLimit - Number of customers to fetch (default: 100)
|
|
114
|
+
* @returns Promise<{count:number, items: CustomerBE[]}> - Paged customers
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* const customers = await getCachedCustomers();
|
|
118
|
+
* console.log(customers.items[0].firstName);
|
|
119
|
+
*
|
|
120
|
+
* // With search
|
|
121
|
+
* const filtered = await getCachedCustomers('John');
|
|
122
|
+
*
|
|
123
|
+
* // With filters
|
|
124
|
+
* const filteredByCountry = await getCachedCustomers(undefined, { country: 'USA' });
|
|
125
|
+
*/
|
|
126
|
+
var getCachedCustomers = function (searchQuery_1, filters_1) {
|
|
127
|
+
var args_1 = [];
|
|
128
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
129
|
+
args_1[_i - 2] = arguments[_i];
|
|
130
|
+
}
|
|
131
|
+
return __awaiter(void 0, __spreadArray([searchQuery_1, filters_1], args_1, true), void 0, function (searchQuery, filters, pageLimit) {
|
|
132
|
+
var response_1, cachedData, currentTime, cachedTime, ageInMs, response, updatedCache, error_1;
|
|
133
|
+
var _a;
|
|
134
|
+
if (pageLimit === void 0) { pageLimit = 100; }
|
|
135
|
+
return __generator(this, function (_b) {
|
|
136
|
+
switch (_b.label) {
|
|
137
|
+
case 0:
|
|
138
|
+
_b.trys.push([0, 4, , 5]);
|
|
139
|
+
if (!((searchQuery && searchQuery.trim()) ||
|
|
140
|
+
(filters && Object.keys(filters).length > 0))) return [3 /*break*/, 2];
|
|
141
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
142
|
+
url: constants_1.API_ROUTES.CUSTOMERS,
|
|
143
|
+
body: JSON.stringify(__assign(__assign({ searchQuery: searchQuery }, filters), { pageLimit: pageLimit, currentPage: 1 })),
|
|
144
|
+
method: api_methods_1.API_METHODS.POST,
|
|
145
|
+
})];
|
|
146
|
+
case 1:
|
|
147
|
+
response_1 = _b.sent();
|
|
148
|
+
return [2 /*return*/, (response_1 === null || response_1 === void 0 ? void 0 : response_1.data) || { count: 0, items: [] }];
|
|
149
|
+
case 2:
|
|
150
|
+
cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.CUSTOMERS);
|
|
151
|
+
currentTime = new Date().getTime();
|
|
152
|
+
// Check if cached data exists and is still fresh
|
|
153
|
+
if (cachedData) {
|
|
154
|
+
cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
155
|
+
ageInMs = currentTime - cachedTime;
|
|
156
|
+
// If cached data is less than 1 day old, return it
|
|
157
|
+
if (ageInMs < constants_1.ONE_DAY_IN_MS) {
|
|
158
|
+
return [2 /*return*/, {
|
|
159
|
+
count: cachedData.customers.length,
|
|
160
|
+
items: cachedData.customers,
|
|
161
|
+
}];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
165
|
+
url: constants_1.API_ROUTES.CUSTOMERS,
|
|
166
|
+
body: JSON.stringify({
|
|
167
|
+
pageLimit: pageLimit,
|
|
168
|
+
currentPage: 1,
|
|
169
|
+
}),
|
|
170
|
+
method: api_methods_1.API_METHODS.POST,
|
|
171
|
+
})];
|
|
172
|
+
case 3:
|
|
173
|
+
response = _b.sent();
|
|
174
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) {
|
|
175
|
+
updatedCache = {
|
|
176
|
+
customers: response.data.items,
|
|
177
|
+
cachedAt: new Date().toISOString(),
|
|
178
|
+
};
|
|
179
|
+
(0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.CUSTOMERS, updatedCache);
|
|
180
|
+
return [2 /*return*/, response.data];
|
|
181
|
+
}
|
|
182
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
183
|
+
case 4:
|
|
184
|
+
error_1 = _b.sent();
|
|
185
|
+
console.error('Error fetching customers:', error_1);
|
|
186
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
187
|
+
case 5: return [2 /*return*/];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
exports.getCachedCustomers = getCachedCustomers;
|
|
193
|
+
/**
|
|
194
|
+
* Utility function to get a specific customer by ID from cache
|
|
195
|
+
* If not found in cache, returns null (does not trigger API call)
|
|
196
|
+
*
|
|
197
|
+
* @param customerId - The ID of the customer to retrieve
|
|
198
|
+
* @returns CustomerBE | null - The customer or null if not found
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* const customer = getCachedCustomerById('customer-123');
|
|
202
|
+
* if (customer) {
|
|
203
|
+
* console.log(customer.firstName);
|
|
204
|
+
* }
|
|
205
|
+
*/
|
|
206
|
+
var getCachedCustomerById = function (customerId) {
|
|
207
|
+
if (!customerId) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
var customers = (0, exports.getCachedCustomersSync)().items;
|
|
212
|
+
return customers.find(function (customer) { return customer.id === customerId; }) || null;
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
console.error('Error getting cached customer by ID:', error);
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
exports.getCachedCustomerById = getCachedCustomerById;
|
|
220
|
+
/**
|
|
221
|
+
* Utility function to get a specific customer by phone from cache
|
|
222
|
+
* If not found in cache, returns null (does not trigger API call)
|
|
223
|
+
*
|
|
224
|
+
* @param phone - The phone number of the customer to search for
|
|
225
|
+
* @returns CustomerBE | null - The customer or null if not found
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* const customer = getCachedCustomerByPhone('+1234567890');
|
|
229
|
+
* if (customer) {
|
|
230
|
+
* console.log(customer.firstName);
|
|
231
|
+
* }
|
|
232
|
+
*/
|
|
233
|
+
var getCachedCustomerByPhone = function (phone) {
|
|
234
|
+
if (!phone) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
var customers = (0, exports.getCachedCustomersSync)().items;
|
|
239
|
+
return customers.find(function (customer) { return customer.phone === phone; }) || null;
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
console.error('Error getting cached customer by phone:', error);
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
exports.getCachedCustomerByPhone = getCachedCustomerByPhone;
|
|
247
|
+
/**
|
|
248
|
+
* Utility function to invalidate (remove) customers from cache
|
|
249
|
+
* Useful when customers have been updated and you want to force a refresh
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* invalidateCustomersCache();
|
|
253
|
+
* const freshCustomers = await getCachedCustomers();
|
|
254
|
+
*/
|
|
255
|
+
var invalidateCustomersCache = function () {
|
|
256
|
+
try {
|
|
257
|
+
localStorage.removeItem(type_1.LS_KEYS.CUSTOMERS);
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
console.error('Error invalidating customers cache:', error);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
exports.invalidateCustomersCache = invalidateCustomersCache;
|
|
264
|
+
/**
|
|
265
|
+
* Utility function to preload customers into cache
|
|
266
|
+
* Useful to call on app initialization or login
|
|
267
|
+
*
|
|
268
|
+
* @returns Promise<{count:number, items: CustomerBE[]}> - Array of preloaded customers
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* // On app initialization
|
|
272
|
+
* await preloadCustomers();
|
|
273
|
+
*/
|
|
274
|
+
var preloadCustomers = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
275
|
+
return __generator(this, function (_a) {
|
|
276
|
+
return [2 /*return*/, (0, exports.getCachedCustomers)()];
|
|
277
|
+
});
|
|
278
|
+
}); };
|
|
279
|
+
exports.preloadCustomers = preloadCustomers;
|
|
280
|
+
/**
|
|
281
|
+
* Utility function to check if customers cache is stale
|
|
282
|
+
* Returns true if cache is older than 1 day or doesn't exist
|
|
283
|
+
*
|
|
284
|
+
* @returns boolean - True if cache is stale or doesn't exist
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* if (isCustomersCacheStale()) {
|
|
288
|
+
* await getCachedCustomers(); // This will fetch fresh data
|
|
289
|
+
* }
|
|
290
|
+
*/
|
|
291
|
+
var isCustomersCacheStale = function () {
|
|
292
|
+
try {
|
|
293
|
+
var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.CUSTOMERS);
|
|
294
|
+
if (!cachedData) {
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
var currentTime = new Date().getTime();
|
|
298
|
+
var cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
299
|
+
var ageInMs = currentTime - cachedTime;
|
|
300
|
+
return ageInMs >= constants_1.ONE_DAY_IN_MS;
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
console.error('Error checking customers cache staleness:', error);
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
exports.isCustomersCacheStale = isCustomersCacheStale;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './cache';
|
|
2
|
+
import { CustomerBE } from '../type';
|
|
2
3
|
type PrismaClient = any;
|
|
3
4
|
export interface ListCustomerArgs {
|
|
4
5
|
currentPage?: number;
|
|
@@ -37,32 +38,31 @@ export interface DeleteCustomerArgs {
|
|
|
37
38
|
/**
|
|
38
39
|
* Retrieves customers with pagination and filtering
|
|
39
40
|
* @param {ListCustomerArgs} args - Object containing prisma client, pagination, and query options
|
|
40
|
-
* @returns {Promise<[number, Array<
|
|
41
|
+
* @returns {Promise<[number, Array<CustomerBE>]>} Tuple containing total count and array of customers
|
|
41
42
|
*/
|
|
42
|
-
export declare const listCustomer: ({ currentPage, includeQuotesInvoices, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListCustomerArgs) => Promise<[number, Array<
|
|
43
|
+
export declare const listCustomer: ({ currentPage, includeQuotesInvoices, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListCustomerArgs) => Promise<[number, Array<CustomerBE>]>;
|
|
43
44
|
/**
|
|
44
45
|
* Retrieves a single customer by ID
|
|
45
46
|
* @param {UnitCustomerByIdArgs} args - Object containing prisma client and query where conditions
|
|
46
|
-
* @returns {Promise<
|
|
47
|
+
* @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
|
|
47
48
|
*/
|
|
48
|
-
export declare const unitCustomerById: ({ id, prisma, includeQuotesInvoices, }: UnitCustomerByIdArgs) => Promise<
|
|
49
|
+
export declare const unitCustomerById: ({ id, prisma, includeQuotesInvoices, }: UnitCustomerByIdArgs) => Promise<CustomerBE | null>;
|
|
49
50
|
/**
|
|
50
51
|
* Retrieves a single customer by phone number
|
|
51
52
|
* @param {UnitCustomerByPhoneArgs} args - Object containing prisma client and phone number
|
|
52
|
-
* @returns {Promise<
|
|
53
|
+
* @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
|
|
53
54
|
*/
|
|
54
|
-
export declare const unitCustomerByPhone: ({ includeQuotesInvoices, phone, prisma, }: UnitCustomerByPhoneArgs) => Promise<
|
|
55
|
+
export declare const unitCustomerByPhone: ({ includeQuotesInvoices, phone, prisma, }: UnitCustomerByPhoneArgs) => Promise<CustomerBE | null>;
|
|
55
56
|
/**
|
|
56
57
|
* Creates or updates a customer
|
|
57
58
|
* @param {UpdateCustomerArgs} args - Object containing prisma client and customer data
|
|
58
|
-
* @returns {Promise<
|
|
59
|
+
* @returns {Promise<CustomerBE>} Created or updated customer
|
|
59
60
|
*/
|
|
60
|
-
export declare const updateCustomer: ({ address, city, country, email, firstName, id, lastName, phone, prisma, }: UpdateCustomerArgs) => Promise<
|
|
61
|
+
export declare const updateCustomer: ({ address, city, country, email, firstName, id, lastName, phone, prisma, }: UpdateCustomerArgs) => Promise<CustomerBE>;
|
|
61
62
|
/**
|
|
62
63
|
* Deletes a customer by ID
|
|
63
64
|
* @param {DeleteCustomerArgs} args - Object containing prisma client and query where conditions
|
|
64
|
-
* @returns {Promise<
|
|
65
|
+
* @returns {Promise<CustomerBE>} Deleted customer
|
|
65
66
|
* @throws {Error} If customer ID is not provided or customer not found
|
|
66
67
|
*/
|
|
67
|
-
export declare const deleteCustomer: ({ id, prisma, }: DeleteCustomerArgs) => Promise<
|
|
68
|
-
export {};
|
|
68
|
+
export declare const deleteCustomer: ({ id, prisma, }: DeleteCustomerArgs) => Promise<CustomerBE>;
|
|
@@ -10,6 +10,20 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
+
};
|
|
13
27
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
28
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
29
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -57,11 +71,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
57
71
|
};
|
|
58
72
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
73
|
exports.deleteCustomer = exports.updateCustomer = exports.unitCustomerByPhone = exports.unitCustomerById = exports.listCustomer = void 0;
|
|
74
|
+
__exportStar(require("./cache"), exports);
|
|
60
75
|
var multi_part_search_1 = require("../../../general/multi-part-search");
|
|
61
76
|
/**
|
|
62
77
|
* Retrieves customers with pagination and filtering
|
|
63
78
|
* @param {ListCustomerArgs} args - Object containing prisma client, pagination, and query options
|
|
64
|
-
* @returns {Promise<[number, Array<
|
|
79
|
+
* @returns {Promise<[number, Array<CustomerBE>]>} Tuple containing total count and array of customers
|
|
65
80
|
*/
|
|
66
81
|
var listCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
67
82
|
var include, orderBy, idSearchQuery, firstNameSearchQuery, lastNameSearchQuery, emailSearchQuery, phoneSearchQuery, where, _c, count, items;
|
|
@@ -127,7 +142,7 @@ exports.listCustomer = listCustomer;
|
|
|
127
142
|
/**
|
|
128
143
|
* Retrieves a single customer by ID
|
|
129
144
|
* @param {UnitCustomerByIdArgs} args - Object containing prisma client and query where conditions
|
|
130
|
-
* @returns {Promise<
|
|
145
|
+
* @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
|
|
131
146
|
*/
|
|
132
147
|
var unitCustomerById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
133
148
|
var include, where, customer;
|
|
@@ -156,7 +171,7 @@ exports.unitCustomerById = unitCustomerById;
|
|
|
156
171
|
/**
|
|
157
172
|
* Retrieves a single customer by phone number
|
|
158
173
|
* @param {UnitCustomerByPhoneArgs} args - Object containing prisma client and phone number
|
|
159
|
-
* @returns {Promise<
|
|
174
|
+
* @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
|
|
160
175
|
*/
|
|
161
176
|
var unitCustomerByPhone = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
162
177
|
var include, where, customer;
|
|
@@ -185,7 +200,7 @@ exports.unitCustomerByPhone = unitCustomerByPhone;
|
|
|
185
200
|
/**
|
|
186
201
|
* Creates or updates a customer
|
|
187
202
|
* @param {UpdateCustomerArgs} args - Object containing prisma client and customer data
|
|
188
|
-
* @returns {Promise<
|
|
203
|
+
* @returns {Promise<CustomerBE>} Created or updated customer
|
|
189
204
|
*/
|
|
190
205
|
var updateCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
191
206
|
var customerData, where, customer;
|
|
@@ -224,7 +239,7 @@ exports.updateCustomer = updateCustomer;
|
|
|
224
239
|
/**
|
|
225
240
|
* Deletes a customer by ID
|
|
226
241
|
* @param {DeleteCustomerArgs} args - Object containing prisma client and query where conditions
|
|
227
|
-
* @returns {Promise<
|
|
242
|
+
* @returns {Promise<CustomerBE>} Deleted customer
|
|
228
243
|
* @throws {Error} If customer ID is not provided or customer not found
|
|
229
244
|
*/
|
|
230
245
|
var deleteCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { ExpenseBE } from '../type';
|
|
2
|
+
/**
|
|
3
|
+
* Synchronous utility function to get expenses from cache only
|
|
4
|
+
* Returns cached data immediately if available and fresh, otherwise returns empty array
|
|
5
|
+
* Does not trigger any API calls
|
|
6
|
+
*
|
|
7
|
+
* @returns ExpenseBE[] - Array of cached expenses or empty array wrapper ({count, items})
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const expenses = getCachedExpensesSync();
|
|
11
|
+
* if (expenses.items.length > 0) {
|
|
12
|
+
* console.log(expenses.items[0].name);
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export declare const getCachedExpensesSync: () => {
|
|
16
|
+
count: number;
|
|
17
|
+
items: ExpenseBE[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Utility function to get expenses from cache or fetch from API
|
|
21
|
+
*
|
|
22
|
+
* This function manages a localStorage cache of expenses with the following logic:
|
|
23
|
+
* - If expenses exist in cache and are less than 1 day old, return cached version
|
|
24
|
+
* - If expenses exist but are older than 1 day, fetch fresh data and update cache
|
|
25
|
+
* - If expenses don't exist in cache, fetch from API and cache them
|
|
26
|
+
*
|
|
27
|
+
* @param searchQuery - Optional search query to filter expenses
|
|
28
|
+
* @param filters - Optional filters object to apply additional filtering (bypasses cache)
|
|
29
|
+
* @param pageLimit - Number of expenses to fetch (default: 100)
|
|
30
|
+
* @returns Promise<{count:number, items: ExpenseBE[]}> - Paged expenses
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const expenses = await getCachedExpenses();
|
|
34
|
+
* console.log(expenses.items[0].name);
|
|
35
|
+
*
|
|
36
|
+
* // With search
|
|
37
|
+
* const filtered = await getCachedExpenses('Office');
|
|
38
|
+
*
|
|
39
|
+
* // With filters
|
|
40
|
+
* const filteredByCategory = await getCachedExpenses(undefined, { expenseCategoryId: 'cat-123' });
|
|
41
|
+
*/
|
|
42
|
+
export declare const getCachedExpenses: (searchQuery?: string, filters?: Record<string, unknown>, pageLimit?: number) => Promise<{
|
|
43
|
+
count: number;
|
|
44
|
+
items: ExpenseBE[];
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Utility function to get a specific expense by ID from cache
|
|
48
|
+
* If not found in cache, returns null (does not trigger API call)
|
|
49
|
+
*
|
|
50
|
+
* @param expenseId - The ID of the expense to retrieve
|
|
51
|
+
* @returns ExpenseBE | null - The expense or null if not found
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const expense = getCachedExpenseById('expense-123');
|
|
55
|
+
* if (expense) {
|
|
56
|
+
* console.log(expense.name);
|
|
57
|
+
* }
|
|
58
|
+
*/
|
|
59
|
+
export declare const getCachedExpenseById: (expenseId: string) => ExpenseBE | null;
|
|
60
|
+
/**
|
|
61
|
+
* Utility function to get expenses by name from cache
|
|
62
|
+
* If not found in cache, returns empty array (does not trigger API call)
|
|
63
|
+
*
|
|
64
|
+
* @param name - The name of the expense to search for
|
|
65
|
+
* @returns ExpenseBE[] - Array of matching expenses or empty array
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const expenses = getCachedExpensesByName('Office');
|
|
69
|
+
* console.log(expenses.length);
|
|
70
|
+
*/
|
|
71
|
+
export declare const getCachedExpensesByName: (name: string) => ExpenseBE[];
|
|
72
|
+
/**
|
|
73
|
+
* Utility function to invalidate (remove) expenses from cache
|
|
74
|
+
* Useful when expenses have been updated and you want to force a refresh
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* invalidateExpensesCache();
|
|
78
|
+
* const freshExpenses = await getCachedExpenses();
|
|
79
|
+
*/
|
|
80
|
+
export declare const invalidateExpensesCache: () => void;
|
|
81
|
+
/**
|
|
82
|
+
* Utility function to preload expenses into cache
|
|
83
|
+
* Useful to call on app initialization or login
|
|
84
|
+
*
|
|
85
|
+
* @returns Promise<{count:number, items: ExpenseBE[]}> - Array of preloaded expenses
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* // On app initialization
|
|
89
|
+
* await preloadExpenses();
|
|
90
|
+
*/
|
|
91
|
+
export declare const preloadExpenses: () => Promise<{
|
|
92
|
+
count: number;
|
|
93
|
+
items: ExpenseBE[];
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Utility function to check if expenses cache is stale
|
|
97
|
+
* Returns true if cache is older than 1 day or doesn't exist
|
|
98
|
+
*
|
|
99
|
+
* @returns boolean - True if cache is stale or doesn't exist
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* if (isExpensesCacheStale()) {
|
|
103
|
+
* await getCachedExpenses(); // This will fetch fresh data
|
|
104
|
+
* }
|
|
105
|
+
*/
|
|
106
|
+
export declare const isExpensesCacheStale: () => boolean;
|