@react-pakistan/util-functions 1.24.93 → 1.24.95

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.
@@ -1,6 +1,8 @@
1
1
  import { ProductBE } from '../type';
2
2
  type PrismaClient = any;
3
3
  export interface ListProductArgs {
4
+ buyPriceMax?: string;
5
+ buyPriceMin?: string;
4
6
  currentPage?: number;
5
7
  includeProductCategory?: boolean;
6
8
  includeQuotesInvoices?: boolean;
@@ -8,6 +10,9 @@ export interface ListProductArgs {
8
10
  orderByDirection?: 'asc' | 'desc';
9
11
  pageLimit?: number;
10
12
  prisma: PrismaClient;
13
+ productCategoryId?: string;
14
+ salePriceMax?: string;
15
+ salePriceMin?: string;
11
16
  searchQuery?: string;
12
17
  }
13
18
  export interface UnitProductByIdArgs {
@@ -39,7 +44,7 @@ export interface DeleteProductArgs {
39
44
  * @param {ListProductArgs} args - Object containing prisma client, pagination, filtering, and ordering options
40
45
  * @returns {Promise<[number, Array<ProductBE>]>} Tuple containing total count and array of products
41
46
  */
42
- export declare const listProduct: ({ currentPage, includeProductCategory, includeQuotesInvoices, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListProductArgs) => Promise<[number, Array<ProductBE>]>;
47
+ export declare const listProduct: ({ buyPriceMax, buyPriceMin, currentPage, includeProductCategory, includeQuotesInvoices, orderByColumn, orderByDirection, pageLimit, prisma, salePriceMax, salePriceMin, searchQuery, }: ListProductArgs) => Promise<[number, Array<ProductBE>]>;
43
48
  /**
44
49
  * Retrieves a single product by its ID
45
50
  * @param {UnitProductByIdArgs} args - Object containing prisma client, product ID, and optional query parameters
@@ -66,9 +66,9 @@ var multi_part_search_1 = require("../../../general/multi-part-search");
66
66
  var listProduct = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
67
67
  var include, orderBy, idSearchQuery, nameSearchQuery, refSearchQuery, where, _c, count, items;
68
68
  var _d;
69
- var _e = _b.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _b.includeProductCategory, includeProductCategory = _f === void 0 ? false : _f, _g = _b.includeQuotesInvoices, includeQuotesInvoices = _g === void 0 ? false : _g, _h = _b.orderByColumn, orderByColumn = _h === void 0 ? 'createdAt' : _h, _j = _b.orderByDirection, orderByDirection = _j === void 0 ? 'desc' : _j, _k = _b.pageLimit, pageLimit = _k === void 0 ? 5 : _k, prisma = _b.prisma, _l = _b.searchQuery, searchQuery = _l === void 0 ? '' : _l;
70
- return __generator(this, function (_m) {
71
- switch (_m.label) {
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) {
72
72
  case 0:
73
73
  if (!currentPage || currentPage < 1) {
74
74
  throw new Error('Valid current page is required');
@@ -96,7 +96,20 @@ var listProduct = function (_a) { return __awaiter(void 0, [_a], void 0, functio
96
96
  fullText: searchQuery,
97
97
  });
98
98
  where = {
99
- OR: __spreadArray(__spreadArray(__spreadArray([], idSearchQuery, true), nameSearchQuery, true), refSearchQuery, true),
99
+ OR: __spreadArray(__spreadArray(__spreadArray(__spreadArray([], idSearchQuery, true), nameSearchQuery, true), refSearchQuery, true), [
100
+ {
101
+ buyPrice: {
102
+ lte: buyPriceMin ? buyPriceMin : undefined,
103
+ gte: buyPriceMax ? buyPriceMax : undefined,
104
+ },
105
+ },
106
+ {
107
+ salePrice: {
108
+ lte: salePriceMin ? salePriceMin : undefined,
109
+ gte: salePriceMax ? salePriceMax : undefined,
110
+ },
111
+ },
112
+ ], false),
100
113
  };
101
114
  return [4 /*yield*/, prisma.$transaction([
102
115
  prisma.product.count({
@@ -111,7 +124,7 @@ var listProduct = function (_a) { return __awaiter(void 0, [_a], void 0, functio
111
124
  }),
112
125
  ])];
113
126
  case 1:
114
- _c = _m.sent(), count = _c[0], items = _c[1];
127
+ _c = _r.sent(), count = _c[0], items = _c[1];
115
128
  return [2 /*return*/, [count, items]];
116
129
  }
117
130
  });
@@ -6,7 +6,7 @@ interface Return {
6
6
  * Get the full month range for a given month and year
7
7
  * @param month - The month (0-11, where 0 is January). Defaults to current month.
8
8
  * @param year - The year. Defaults to current year.
9
- * @returns An object containing startOfMonth and endOfMonth dates
9
+ * @returns An object containing startOfMonth and endOfMonth dates in UTC
10
10
  */
11
11
  export declare const fullMonthRange: (month?: number, year?: number) => Return;
12
12
  export {};
@@ -5,17 +5,17 @@ exports.fullMonthRange = void 0;
5
5
  * Get the full month range for a given month and year
6
6
  * @param month - The month (0-11, where 0 is January). Defaults to current month.
7
7
  * @param year - The year. Defaults to current year.
8
- * @returns An object containing startOfMonth and endOfMonth dates
8
+ * @returns An object containing startOfMonth and endOfMonth dates in UTC
9
9
  */
10
10
  var fullMonthRange = function (month, year) {
11
11
  var now = new Date();
12
12
  var targetYear = year !== null && year !== void 0 ? year : now.getUTCFullYear();
13
13
  var targetMonth = month !== null && month !== void 0 ? month : now.getUTCMonth();
14
- // Start of month: first day at 00:00:00.000
15
- var startOfMonth = new Date(targetYear, targetMonth, 1, 0, 0, 0, 0);
16
- // End of month: last day at 23:59:59.999
14
+ // Start of month: first day at 00:00:00.000 UTC
15
+ var startOfMonth = new Date(Date.UTC(targetYear, targetMonth, 1, 0, 0, 0, 0));
16
+ // End of month: last day at 23:59:59.999 UTC
17
17
  // Setting day to 0 of next month gives us the last day of current month
18
- var endOfMonth = new Date(targetYear, targetMonth + 1, 0, 23, 59, 59, 999);
18
+ var endOfMonth = new Date(Date.UTC(targetYear, targetMonth + 1, 0, 23, 59, 59, 999));
19
19
  return {
20
20
  startOfMonth: startOfMonth,
21
21
  endOfMonth: endOfMonth,
@@ -7,11 +7,11 @@ exports.fullYearRange = void 0;
7
7
  * @returns An object containing startOfYear and endOfYear dates
8
8
  */
9
9
  var fullYearRange = function (year) {
10
- var targetYear = year !== null && year !== void 0 ? year : new Date().getFullYear();
10
+ var targetYear = year !== null && year !== void 0 ? year : new Date().getUTCFullYear();
11
11
  // Start of year: January 1st at 00:00:00.000
12
- var startOfYear = new Date(targetYear, 0, 1, 0, 0, 0, 0);
12
+ var startOfYear = new Date(Date.UTC(targetYear, 0, 1, 0, 0, 0, 0));
13
13
  // End of year: December 31st at 23:59:59.999
14
- var endOfYear = new Date(targetYear, 11, 31, 23, 59, 59, 999);
14
+ var endOfYear = new Date(Date.UTC(targetYear, 11, 31, 23, 59, 59, 999));
15
15
  return {
16
16
  startOfYear: startOfYear,
17
17
  endOfYear: endOfYear,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.24.93",
3
+ "version": "1.24.95",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {