@react-pakistan/util-functions 1.24.98 → 1.24.99

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.
Files changed (53) hide show
  1. package/api/stellar-solutions/app-user/index.d.ts +9 -9
  2. package/api/stellar-solutions/app-user/index.js +4 -4
  3. package/api/stellar-solutions/bank/index.d.ts +9 -9
  4. package/api/stellar-solutions/bank/index.js +4 -4
  5. package/api/stellar-solutions/branch/index.d.ts +9 -9
  6. package/api/stellar-solutions/branch/index.js +4 -4
  7. package/api/stellar-solutions/company/index.d.ts +9 -9
  8. package/api/stellar-solutions/company/index.js +4 -4
  9. package/api/stellar-solutions/company-report/index.d.ts +3 -3
  10. package/api/stellar-solutions/company-report/index.js +1 -1
  11. package/api/stellar-solutions/constants.d.ts +9 -0
  12. package/api/stellar-solutions/constants.js +12 -0
  13. package/api/stellar-solutions/contact/index.d.ts +9 -9
  14. package/api/stellar-solutions/contact/index.js +4 -4
  15. package/api/stellar-solutions/currency/index.d.ts +9 -9
  16. package/api/stellar-solutions/currency/index.js +4 -4
  17. package/api/stellar-solutions/customer/index.d.ts +11 -11
  18. package/api/stellar-solutions/customer/index.js +5 -5
  19. package/api/stellar-solutions/expense/index.d.ts +9 -9
  20. package/api/stellar-solutions/expense/index.js +4 -4
  21. package/api/stellar-solutions/expense-category/index.d.ts +9 -9
  22. package/api/stellar-solutions/expense-category/index.js +4 -4
  23. package/api/stellar-solutions/lead/index.d.ts +9 -9
  24. package/api/stellar-solutions/lead/index.js +4 -4
  25. package/api/stellar-solutions/menu-order/index.d.ts +9 -9
  26. package/api/stellar-solutions/menu-order/index.js +4 -4
  27. package/api/stellar-solutions/payment/index.d.ts +9 -9
  28. package/api/stellar-solutions/payment/index.js +4 -4
  29. package/api/stellar-solutions/payment-mode/index.d.ts +9 -9
  30. package/api/stellar-solutions/payment-mode/index.js +4 -4
  31. package/api/stellar-solutions/preference/index.d.ts +5 -5
  32. package/api/stellar-solutions/preference/index.js +2 -2
  33. package/api/stellar-solutions/product/cache.d.ts +94 -0
  34. package/api/stellar-solutions/product/cache.js +280 -0
  35. package/api/stellar-solutions/product/index.d.ts +12 -14
  36. package/api/stellar-solutions/product/index.js +28 -12
  37. package/api/stellar-solutions/product-category/cache.d.ts +94 -0
  38. package/api/stellar-solutions/product-category/cache.js +280 -0
  39. package/api/stellar-solutions/product-category/index.d.ts +10 -10
  40. package/api/stellar-solutions/product-category/index.js +19 -4
  41. package/api/stellar-solutions/profile/index.d.ts +13 -13
  42. package/api/stellar-solutions/profile/index.js +6 -6
  43. package/api/stellar-solutions/quote-invoice/index.d.ts +9 -9
  44. package/api/stellar-solutions/quote-invoice/index.js +4 -4
  45. package/api/stellar-solutions/quote-invoice-report/index.d.ts +3 -3
  46. package/api/stellar-solutions/quote-invoice-report/index.js +1 -1
  47. package/api/stellar-solutions/tax/index.d.ts +9 -9
  48. package/api/stellar-solutions/tax/index.js +4 -4
  49. package/api/stellar-solutions/type.d.ts +49 -45
  50. package/api/stellar-solutions/type.js +6 -1
  51. package/index.d.ts +6 -5
  52. package/index.js +6 -6
  53. package/package.json +1 -1
@@ -0,0 +1,280 @@
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.isProductsCacheStale = exports.preloadProducts = exports.invalidateProductsCache = exports.getCachedProductById = exports.getCachedProducts = exports.getCachedProductsSync = 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 products 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 ProductTypeBE[] - Array of cached products or empty array wrapper ({count, items})
72
+ *
73
+ * @example
74
+ * const products = getCachedProductsSync();
75
+ * if (products.items.length > 0) {
76
+ * console.log(products.items[0].name);
77
+ * }
78
+ */
79
+ var getCachedProductsSync = function () {
80
+ try {
81
+ var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.PRODUCTS);
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.products.length,
92
+ items: cachedData.products,
93
+ };
94
+ }
95
+ return { count: 0, items: [] };
96
+ }
97
+ catch (error) {
98
+ console.error('Error getting cached products:', error);
99
+ return { count: 0, items: [] };
100
+ }
101
+ };
102
+ exports.getCachedProductsSync = getCachedProductsSync;
103
+ /**
104
+ * Utility function to get products from cache or fetch from API
105
+ *
106
+ * This function manages a localStorage cache of products with the following logic:
107
+ * - If products exist in cache and are less than 1 day old, return cached version
108
+ * - If products exist but are older than 1 day, fetch fresh data and update cache
109
+ * - If products don't exist in cache, fetch from API and cache them
110
+ *
111
+ * @param searchQuery - Optional search query to filter products
112
+ * @param filters - Optional filters object to apply additional filtering (bypasses cache)
113
+ * @param pageLimit - Number of products to fetch (default: 100)
114
+ * @returns Promise<{count:number, items: ProductTypeBE[]}> - Paged products
115
+ *
116
+ * @example
117
+ * const products = await getCachedProducts();
118
+ * console.log(products.items[0].name);
119
+ *
120
+ * // With search
121
+ * const filtered = await getCachedProducts('Samsung');
122
+ *
123
+ * // With filters
124
+ * const filteredByCategory = await getCachedProducts(undefined, { productCategoryId: 'cat-123' });
125
+ */
126
+ var getCachedProducts = 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.PRODUCTS,
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.PRODUCTS);
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.products.length,
160
+ items: cachedData.products,
161
+ }];
162
+ }
163
+ }
164
+ return [4 /*yield*/, (0, fetch_data_1.fetchData)({
165
+ url: constants_1.API_ROUTES.PRODUCTS,
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
+ products: response.data.items,
177
+ cachedAt: new Date().toISOString(),
178
+ };
179
+ (0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.PRODUCTS, 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 products:', error_1);
186
+ return [2 /*return*/, { count: 0, items: [] }];
187
+ case 5: return [2 /*return*/];
188
+ }
189
+ });
190
+ });
191
+ };
192
+ exports.getCachedProducts = getCachedProducts;
193
+ /**
194
+ * Utility function to get a specific product by ID from cache
195
+ * If not found in cache, returns null (does not trigger API call)
196
+ *
197
+ * @param productId - The ID of the product to retrieve
198
+ * @returns ProductTypeBE | null - The product or null if not found
199
+ *
200
+ * @example
201
+ * const product = getCachedProductById('prod-123');
202
+ * if (product) {
203
+ * console.log(product.name);
204
+ * }
205
+ */
206
+ var getCachedProductById = function (categoryId) {
207
+ if (!categoryId) {
208
+ return null;
209
+ }
210
+ try {
211
+ var products = (0, exports.getCachedProductsSync)().items;
212
+ return products.find(function (cat) { return cat.id === categoryId; }) || null;
213
+ }
214
+ catch (error) {
215
+ console.error('Error getting cached product by ID:', error);
216
+ return null;
217
+ }
218
+ };
219
+ exports.getCachedProductById = getCachedProductById;
220
+ /**
221
+ * Utility function to invalidate (remove) products from cache
222
+ * Useful when products have been updated and you want to force a refresh
223
+ *
224
+ * @example
225
+ * invalidateProductsCache();
226
+ * const freshProducts = await getCachedProducts();
227
+ */
228
+ var invalidateProductsCache = function () {
229
+ try {
230
+ localStorage.removeItem(type_1.LS_KEYS.PRODUCTS);
231
+ }
232
+ catch (error) {
233
+ console.error('Error invalidating products cache:', error);
234
+ }
235
+ };
236
+ exports.invalidateProductsCache = invalidateProductsCache;
237
+ /**
238
+ * Utility function to preload products into cache
239
+ * Useful to call on app initialization or login
240
+ *
241
+ * @returns Promise<{count:number, items: ProductTypeBE[]}> - Array of preloaded products
242
+ *
243
+ * @example
244
+ * // On app initialization
245
+ * await preloadProducts();
246
+ */
247
+ var preloadProducts = function () { return __awaiter(void 0, void 0, void 0, function () {
248
+ return __generator(this, function (_a) {
249
+ return [2 /*return*/, (0, exports.getCachedProducts)()];
250
+ });
251
+ }); };
252
+ exports.preloadProducts = preloadProducts;
253
+ /**
254
+ * Utility function to check if products cache is stale
255
+ * Returns true if cache is older than 1 day or doesn't exist
256
+ *
257
+ * @returns boolean - True if cache is stale or doesn't exist
258
+ *
259
+ * @example
260
+ * if (isProductsCacheStale()) {
261
+ * await getCachedProducts(); // This will fetch fresh data
262
+ * }
263
+ */
264
+ var isProductsCacheStale = function () {
265
+ try {
266
+ var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.PRODUCTS);
267
+ if (!cachedData) {
268
+ return true;
269
+ }
270
+ var currentTime = new Date().getTime();
271
+ var cachedTime = new Date(cachedData.cachedAt).getTime();
272
+ var ageInMs = currentTime - cachedTime;
273
+ return ageInMs >= constants_1.ONE_DAY_IN_MS;
274
+ }
275
+ catch (error) {
276
+ console.error('Error checking products cache staleness:', error);
277
+ return true;
278
+ }
279
+ };
280
+ exports.isProductsCacheStale = isProductsCacheStale;
@@ -1,8 +1,8 @@
1
- import { ProductBE } from '../type';
1
+ export * from './cache';
2
+ import { ProductTypeBE } from '../type';
2
3
  type PrismaClient = any;
3
4
  export interface ListProductArgs {
4
- buyPriceMax?: string;
5
- buyPriceMin?: string;
5
+ buyPrice?: number;
6
6
  currentPage?: number;
7
7
  includeProductCategory?: boolean;
8
8
  includeQuotesInvoices?: boolean;
@@ -11,8 +11,7 @@ export interface ListProductArgs {
11
11
  pageLimit?: number;
12
12
  prisma: PrismaClient;
13
13
  productCategoryId?: string;
14
- salePriceMax?: string;
15
- salePriceMin?: string;
14
+ salePrice?: number;
16
15
  searchQuery?: string;
17
16
  }
18
17
  export interface UnitProductByIdArgs {
@@ -42,25 +41,24 @@ export interface DeleteProductArgs {
42
41
  /**
43
42
  * Retrieves a paginated list of products
44
43
  * @param {ListProductArgs} args - Object containing prisma client, pagination, filtering, and ordering options
45
- * @returns {Promise<[number, Array<ProductBE>]>} Tuple containing total count and array of products
44
+ * @returns {Promise<[number, Array<ProductTypeBE>]>} Tuple containing total count and array of products
46
45
  */
47
- export declare const listProduct: ({ buyPriceMax, buyPriceMin, currentPage, includeProductCategory, includeQuotesInvoices, orderByColumn, orderByDirection, pageLimit, prisma, salePriceMax, salePriceMin, searchQuery, }: ListProductArgs) => Promise<[number, Array<ProductBE>]>;
46
+ export declare const listProduct: ({ buyPrice, currentPage, includeProductCategory, includeQuotesInvoices, orderByColumn, orderByDirection, pageLimit, prisma, productCategoryId, salePrice, searchQuery, }: ListProductArgs) => Promise<[number, Array<ProductTypeBE>]>;
48
47
  /**
49
48
  * Retrieves a single product by its ID
50
49
  * @param {UnitProductByIdArgs} args - Object containing prisma client, product ID, and optional query parameters
51
- * @returns {Promise<ProductBE | null>} Product or null if not found
50
+ * @returns {Promise<ProductTypeBE | null>} Product or null if not found
52
51
  */
53
- export declare const unitProductById: ({ id, includeProductCategory, includeQuotesInvoices, prisma, }: UnitProductByIdArgs) => Promise<ProductBE | null>;
52
+ export declare const unitProductById: ({ id, includeProductCategory, includeQuotesInvoices, prisma, }: UnitProductByIdArgs) => Promise<ProductTypeBE | null>;
54
53
  /**
55
54
  * Creates or updates a product
56
55
  * @param {UpdateProductArgs} args - Object containing prisma client, product data, and optional query parameters
57
- * @returns {Promise<ProductBE>} Created or updated product
56
+ * @returns {Promise<ProductTypeBE>} Created or updated product
58
57
  */
59
- export declare const updateProduct: ({ buyPrice, currency, description, id, image, name, prisma, productCategoryId, quantity, ref, salePrice, }: UpdateProductArgs) => Promise<ProductBE>;
58
+ export declare const updateProduct: ({ buyPrice, currency, description, id, image, name, prisma, productCategoryId, quantity, ref, salePrice, }: UpdateProductArgs) => Promise<ProductTypeBE>;
60
59
  /**
61
60
  * Deletes a product by ID
62
61
  * @param {DeleteProductArgs} args - Object containing prisma client, product ID, and optional query parameters
63
- * @returns {Promise<ProductBE>} Deleted product
62
+ * @returns {Promise<ProductTypeBE>} Deleted product
64
63
  */
65
- export declare const deleteProduct: ({ id, prisma, }: DeleteProductArgs) => Promise<ProductBE>;
66
- export {};
64
+ export declare const deleteProduct: ({ id, prisma, }: DeleteProductArgs) => Promise<ProductTypeBE>;
@@ -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,18 +71,19 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
57
71
  };
58
72
  Object.defineProperty(exports, "__esModule", { value: true });
59
73
  exports.deleteProduct = exports.updateProduct = exports.unitProductById = exports.listProduct = void 0;
74
+ __exportStar(require("./cache"), exports);
60
75
  var multi_part_search_1 = require("../../../general/multi-part-search");
61
76
  /**
62
77
  * Retrieves a paginated list of products
63
78
  * @param {ListProductArgs} args - Object containing prisma client, pagination, filtering, and ordering options
64
- * @returns {Promise<[number, Array<ProductBE>]>} Tuple containing total count and array of products
79
+ * @returns {Promise<[number, Array<ProductTypeBE>]>} Tuple containing total count and array of products
65
80
  */
66
81
  var listProduct = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
67
82
  var include, orderBy, idSearchQuery, nameSearchQuery, refSearchQuery, where, _c, count, items;
68
83
  var _d;
69
- var _e = _b.buyPriceMax, buyPriceMax = _e === void 0 ? '' : _e, _f = _b.buyPriceMin, buyPriceMin = _f === void 0 ? '' : _f, _g = _b.currentPage, currentPage = _g === void 0 ? 1 : _g, _h = _b.includeProductCategory, includeProductCategory = _h === void 0 ? false : _h, _j = _b.includeQuotesInvoices, includeQuotesInvoices = _j === void 0 ? false : _j, _k = _b.orderByColumn, orderByColumn = _k === void 0 ? 'createdAt' : _k, _l = _b.orderByDirection, orderByDirection = _l === void 0 ? 'desc' : _l, _m = _b.pageLimit, pageLimit = _m === void 0 ? 5 : _m, prisma = _b.prisma, _o = _b.salePriceMax, salePriceMax = _o === void 0 ? '' : _o, _p = _b.salePriceMin, salePriceMin = _p === void 0 ? '' : _p, _q = _b.searchQuery, searchQuery = _q === void 0 ? '' : _q;
70
- return __generator(this, function (_r) {
71
- switch (_r.label) {
84
+ var _e = _b.buyPrice, buyPrice = _e === void 0 ? 0 : _e, _f = _b.currentPage, currentPage = _f === void 0 ? 1 : _f, _g = _b.includeProductCategory, includeProductCategory = _g === void 0 ? false : _g, _h = _b.includeQuotesInvoices, includeQuotesInvoices = _h === void 0 ? false : _h, _j = _b.orderByColumn, orderByColumn = _j === void 0 ? 'createdAt' : _j, _k = _b.orderByDirection, orderByDirection = _k === void 0 ? 'desc' : _k, _l = _b.pageLimit, pageLimit = _l === void 0 ? 5 : _l, prisma = _b.prisma, _m = _b.productCategoryId, productCategoryId = _m === void 0 ? '' : _m, _o = _b.salePrice, salePrice = _o === void 0 ? 0 : _o, _p = _b.searchQuery, searchQuery = _p === void 0 ? '' : _p;
85
+ return __generator(this, function (_q) {
86
+ switch (_q.label) {
72
87
  case 0:
73
88
  if (!currentPage || currentPage < 1) {
74
89
  throw new Error('Valid current page is required');
@@ -96,13 +111,14 @@ var listProduct = function (_a) { return __awaiter(void 0, [_a], void 0, functio
96
111
  fullText: searchQuery,
97
112
  });
98
113
  where = {
114
+ productCategoryId: productCategoryId || undefined,
99
115
  buyPrice: {
100
- lte: buyPriceMin ? buyPriceMin : undefined,
101
- gte: buyPriceMax ? buyPriceMax : undefined,
116
+ lte: buyPrice || undefined,
117
+ gte: buyPrice || undefined,
102
118
  },
103
119
  salePrice: {
104
- lte: salePriceMin ? salePriceMin : undefined,
105
- gte: salePriceMax ? salePriceMax : undefined,
120
+ lte: salePrice || undefined,
121
+ gte: salePrice || undefined,
106
122
  },
107
123
  OR: __spreadArray(__spreadArray(__spreadArray([], idSearchQuery, true), nameSearchQuery, true), refSearchQuery, true),
108
124
  };
@@ -119,7 +135,7 @@ var listProduct = function (_a) { return __awaiter(void 0, [_a], void 0, functio
119
135
  }),
120
136
  ])];
121
137
  case 1:
122
- _c = _r.sent(), count = _c[0], items = _c[1];
138
+ _c = _q.sent(), count = _c[0], items = _c[1];
123
139
  return [2 /*return*/, [count, items]];
124
140
  }
125
141
  });
@@ -128,7 +144,7 @@ exports.listProduct = listProduct;
128
144
  /**
129
145
  * Retrieves a single product by its ID
130
146
  * @param {UnitProductByIdArgs} args - Object containing prisma client, product ID, and optional query parameters
131
- * @returns {Promise<ProductBE | null>} Product or null if not found
147
+ * @returns {Promise<ProductTypeBE | null>} Product or null if not found
132
148
  */
133
149
  var unitProductById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
134
150
  var include, where, product;
@@ -160,7 +176,7 @@ exports.unitProductById = unitProductById;
160
176
  /**
161
177
  * Creates or updates a product
162
178
  * @param {UpdateProductArgs} args - Object containing prisma client, product data, and optional query parameters
163
- * @returns {Promise<ProductBE>} Created or updated product
179
+ * @returns {Promise<ProductTypeBE>} Created or updated product
164
180
  */
165
181
  var updateProduct = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
166
182
  var productData, where, product;
@@ -208,7 +224,7 @@ exports.updateProduct = updateProduct;
208
224
  /**
209
225
  * Deletes a product by ID
210
226
  * @param {DeleteProductArgs} args - Object containing prisma client, product ID, and optional query parameters
211
- * @returns {Promise<ProductBE>} Deleted product
227
+ * @returns {Promise<ProductTypeBE>} Deleted product
212
228
  */
213
229
  var deleteProduct = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
214
230
  var where, product;
@@ -0,0 +1,94 @@
1
+ import { ProductCategoryTypeBE } from '../type';
2
+ /**
3
+ * Synchronous utility function to get product categories 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 ProductCategoryTypeBE[] - Array of cached product categories or empty array
8
+ *
9
+ * @example
10
+ * const categories = getCachedProductCategoriesSync();
11
+ * if (categories.length > 0) {
12
+ * console.log(categories[0].name);
13
+ * }
14
+ */
15
+ export declare const getCachedProductCategoriesSync: () => {
16
+ count: number;
17
+ items: ProductCategoryTypeBE[];
18
+ };
19
+ /**
20
+ * Utility function to get product categories from cache or fetch from API
21
+ *
22
+ * This function manages a localStorage cache of product categories with the following logic:
23
+ * - If categories exist in cache and are less than 1 week old, return cached version
24
+ * - If categories exist but are older than 1 week, fetch fresh data and update cache
25
+ * - If categories don't exist in cache, fetch from API and cache them
26
+ *
27
+ * @param searchQuery - Optional search query to filter categories
28
+ * @param filters - Optional filters object to apply additional filtering (bypasses cache)
29
+ * @param pageLimit - Number of categories to fetch (default: 100)
30
+ * @returns Promise<ProductCategoryTypeBE[]> - Array of product categories
31
+ *
32
+ * @example
33
+ * const categories = await getCachedProductCategories();
34
+ * console.log(categories[0].name);
35
+ *
36
+ * // With search
37
+ * const filtered = await getCachedProductCategories('Electronics');
38
+ *
39
+ * // With filters
40
+ * const filteredCategories = await getCachedProductCategories(undefined, { enabled: true });
41
+ */
42
+ export declare const getCachedProductCategories: (searchQuery?: string, filters?: Record<string, unknown>, pageLimit?: number) => Promise<{
43
+ count: number;
44
+ items: ProductCategoryTypeBE[];
45
+ }>;
46
+ /**
47
+ * Utility function to get a specific product category by ID from cache
48
+ * If not found in cache, returns null (does not trigger API call)
49
+ *
50
+ * @param categoryId - The ID of the category to retrieve
51
+ * @returns ProductCategoryTypeBE | null - The category or null if not found
52
+ *
53
+ * @example
54
+ * const category = getCachedProductCategoryById('cat-123');
55
+ * if (category) {
56
+ * console.log(category.name);
57
+ * }
58
+ */
59
+ export declare const getCachedProductCategoryById: (categoryId: string) => ProductCategoryTypeBE | null;
60
+ /**
61
+ * Utility function to invalidate (remove) product categories from cache
62
+ * Useful when categories have been updated and you want to force a refresh
63
+ *
64
+ * @example
65
+ * invalidateProductCategoriesCache();
66
+ * const freshCategories = await getCachedProductCategories();
67
+ */
68
+ export declare const invalidateProductCategoriesCache: () => void;
69
+ /**
70
+ * Utility function to preload product categories into cache
71
+ * Useful to call on app initialization or login
72
+ *
73
+ * @returns Promise<ProductCategoryTypeBE[]> - Array of preloaded categories
74
+ *
75
+ * @example
76
+ * // On app initialization
77
+ * await preloadProductCategories();
78
+ */
79
+ export declare const preloadProductCategories: () => Promise<{
80
+ count: number;
81
+ items: ProductCategoryTypeBE[];
82
+ }>;
83
+ /**
84
+ * Utility function to check if product categories cache is stale
85
+ * Returns true if cache is older than 1 week or doesn't exist
86
+ *
87
+ * @returns boolean - True if cache is stale or doesn't exist
88
+ *
89
+ * @example
90
+ * if (isProductCategoriesCacheStale()) {
91
+ * await getCachedProductCategories(); // This will fetch fresh data
92
+ * }
93
+ */
94
+ export declare const isProductCategoriesCacheStale: () => boolean;