@react-pakistan/util-functions 1.24.66 → 1.24.67

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.
@@ -2,17 +2,18 @@ import { ProductBE } from '../type';
2
2
  type PrismaClient = any;
3
3
  interface ListProductArgs {
4
4
  currentPage?: number;
5
- include?: any;
6
- orderBy?: any;
5
+ includeProductCategory?: boolean;
6
+ includeQuotesInvoices?: boolean;
7
+ orderByColumn?: string;
8
+ orderByDirection?: 'asc' | 'desc';
7
9
  pageLimit?: number;
8
10
  prisma: PrismaClient;
9
- queryWhere?: any;
10
11
  }
11
12
  interface UnitProductByIdArgs {
12
13
  id: string;
13
- include?: any;
14
+ includeProductCategory?: boolean;
15
+ includeQuotesInvoices?: boolean;
14
16
  prisma: PrismaClient;
15
- queryWhere?: any;
16
17
  }
17
18
  interface UpdateProductArgs {
18
19
  buyPrice: string;
@@ -20,43 +21,44 @@ interface UpdateProductArgs {
20
21
  description?: string;
21
22
  id: string;
22
23
  image?: string;
23
- name: string;
24
24
  include?: any;
25
+ includeProductCategory?: boolean;
26
+ includeQuotesInvoices?: boolean;
27
+ name: string;
25
28
  prisma: PrismaClient;
26
29
  productCategoryId: string;
27
30
  quantity: string;
28
- queryWhere?: any;
29
31
  ref?: string;
30
32
  salePrice: string;
31
33
  }
32
34
  interface DeleteProductArgs {
33
35
  id: string;
34
- include?: any;
36
+ includeProductCategory?: boolean;
37
+ includeQuotesInvoices?: boolean;
35
38
  prisma: PrismaClient;
36
- queryWhere?: any;
37
39
  }
38
40
  /**
39
41
  * Retrieves a paginated list of products
40
42
  * @param {ListProductArgs} args - Object containing prisma client, pagination, filtering, and ordering options
41
43
  * @returns {Promise<[number, Array<ProductBE>]>} Tuple containing total count and array of products
42
44
  */
43
- export declare const listProduct: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: ListProductArgs) => Promise<[number, Array<ProductBE>]>;
45
+ export declare const listProduct: ({ currentPage, includeProductCategory, includeQuotesInvoices, orderByColumn, orderByDirection, pageLimit, prisma, }: ListProductArgs) => Promise<[number, Array<ProductBE>]>;
44
46
  /**
45
47
  * Retrieves a single product by its ID
46
48
  * @param {UnitProductByIdArgs} args - Object containing prisma client, product ID, and optional query parameters
47
49
  * @returns {Promise<ProductBE | null>} Product or null if not found
48
50
  */
49
- export declare const unitProductById: ({ id, include, prisma, queryWhere, }: UnitProductByIdArgs) => Promise<ProductBE | null>;
51
+ export declare const unitProductById: ({ id, includeProductCategory, includeQuotesInvoices, prisma, }: UnitProductByIdArgs) => Promise<ProductBE | null>;
50
52
  /**
51
53
  * Creates or updates a product
52
54
  * @param {UpdateProductArgs} args - Object containing prisma client, product data, and optional query parameters
53
55
  * @returns {Promise<ProductBE>} Created or updated product
54
56
  */
55
- export declare const updateProduct: ({ buyPrice, currency, description, id, image, include, name, prisma, productCategoryId, quantity, queryWhere, ref, salePrice, }: UpdateProductArgs) => Promise<ProductBE>;
57
+ export declare const updateProduct: ({ buyPrice, currency, description, id, image, includeProductCategory, includeQuotesInvoices, name, prisma, productCategoryId, quantity, ref, salePrice, }: UpdateProductArgs) => Promise<ProductBE>;
56
58
  /**
57
59
  * Deletes a product by ID
58
60
  * @param {DeleteProductArgs} args - Object containing prisma client, product ID, and optional query parameters
59
61
  * @returns {Promise<ProductBE>} Deleted product
60
62
  */
61
- export declare const deleteProduct: ({ id, include, prisma, queryWhere, }: DeleteProductArgs) => Promise<ProductBE>;
63
+ export declare const deleteProduct: ({ id, includeProductCategory, includeQuotesInvoices, prisma, }: DeleteProductArgs) => Promise<ProductBE>;
62
64
  export {};
@@ -54,13 +54,11 @@ exports.deleteProduct = exports.updateProduct = exports.unitProductById = export
54
54
  * @returns {Promise<[number, Array<ProductBE>]>} Tuple containing total count and array of products
55
55
  */
56
56
  var listProduct = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var skip, _c, count, data;
58
- var _d = _b.currentPage, currentPage = _d === void 0 ? 1 : _d, _e = _b.include, include = _e === void 0 ? {
59
- productCategory: true,
60
- quotesInvoices: true,
61
- } : _e, _f = _b.orderBy, orderBy = _f === void 0 ? { createdAt: 'desc' } : _f, _g = _b.pageLimit, pageLimit = _g === void 0 ? 10 : _g, prisma = _b.prisma, _h = _b.queryWhere, queryWhere = _h === void 0 ? {} : _h;
62
- return __generator(this, function (_j) {
63
- switch (_j.label) {
57
+ var include, orderBy, skip, where, _c, count, items;
58
+ var _d;
59
+ 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 ? 10 : _k, prisma = _b.prisma;
60
+ return __generator(this, function (_l) {
61
+ switch (_l.label) {
64
62
  case 0:
65
63
  if (currentPage < 1) {
66
64
  throw new Error('Current page must be greater than or equal to 1');
@@ -68,22 +66,30 @@ var listProduct = function (_a) { return __awaiter(void 0, [_a], void 0, functio
68
66
  if (pageLimit < 1) {
69
67
  throw new Error('Page limit must be greater than or equal to 1');
70
68
  }
69
+ include = {
70
+ productCategory: includeProductCategory,
71
+ quotesInvoices: includeQuotesInvoices,
72
+ };
73
+ orderBy = (_d = {},
74
+ _d[orderByColumn] = orderByDirection,
75
+ _d);
71
76
  skip = (currentPage - 1) * pageLimit;
72
- return [4 /*yield*/, Promise.all([
77
+ where = {};
78
+ return [4 /*yield*/, prisma.$transaction([
73
79
  prisma.product.count({
74
- where: queryWhere,
80
+ where: where,
75
81
  }),
76
82
  prisma.product.findMany({
77
- include: include || null,
83
+ include: include,
78
84
  orderBy: orderBy,
79
85
  skip: skip,
80
86
  take: pageLimit,
81
- where: queryWhere,
87
+ where: where,
82
88
  }),
83
89
  ])];
84
90
  case 1:
85
- _c = _j.sent(), count = _c[0], data = _c[1];
86
- return [2 /*return*/, [count, data]];
91
+ _c = _l.sent(), count = _c[0], items = _c[1];
92
+ return [2 /*return*/, [count, items]];
87
93
  }
88
94
  });
89
95
  }); };
@@ -94,23 +100,24 @@ exports.listProduct = listProduct;
94
100
  * @returns {Promise<ProductBE | null>} Product or null if not found
95
101
  */
96
102
  var unitProductById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
97
- var product;
98
- var id = _b.id, _c = _b.include, include = _c === void 0 ? {
99
- productCategory: true,
100
- quotesInvoices: true,
101
- } : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
103
+ var include, where, product;
104
+ var id = _b.id, _c = _b.includeProductCategory, includeProductCategory = _c === void 0 ? false : _c, _d = _b.includeQuotesInvoices, includeQuotesInvoices = _d === void 0 ? false : _d, prisma = _b.prisma;
102
105
  return __generator(this, function (_e) {
103
106
  switch (_e.label) {
104
107
  case 0:
105
108
  if (!id) {
106
109
  throw new Error('Product ID is required');
107
110
  }
108
- if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
109
- throw new Error('ID mismatch between parameter and queryWhere');
110
- }
111
+ include = {
112
+ productCategory: includeProductCategory,
113
+ quotesInvoices: includeQuotesInvoices,
114
+ };
115
+ where = {
116
+ id: id,
117
+ };
111
118
  return [4 /*yield*/, prisma.product.findUnique({
112
- include: include || null,
113
- where: __assign({ id: id }, queryWhere),
119
+ include: include,
120
+ where: where,
114
121
  })];
115
122
  case 1:
116
123
  product = _e.sent();
@@ -125,11 +132,8 @@ exports.unitProductById = unitProductById;
125
132
  * @returns {Promise<ProductBE>} Created or updated product
126
133
  */
127
134
  var updateProduct = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
128
- var productData, product;
129
- var buyPrice = _b.buyPrice, currency = _b.currency, description = _b.description, id = _b.id, image = _b.image, _c = _b.include, include = _c === void 0 ? {
130
- productCategory: true,
131
- quotesInvoices: true,
132
- } : _c, name = _b.name, prisma = _b.prisma, productCategoryId = _b.productCategoryId, quantity = _b.quantity, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d, ref = _b.ref, salePrice = _b.salePrice;
135
+ var productData, include, where, product;
136
+ var buyPrice = _b.buyPrice, currency = _b.currency, description = _b.description, id = _b.id, image = _b.image, _c = _b.includeProductCategory, includeProductCategory = _c === void 0 ? true : _c, _d = _b.includeQuotesInvoices, includeQuotesInvoices = _d === void 0 ? true : _d, name = _b.name, prisma = _b.prisma, productCategoryId = _b.productCategoryId, quantity = _b.quantity, ref = _b.ref, salePrice = _b.salePrice;
133
137
  return __generator(this, function (_e) {
134
138
  switch (_e.label) {
135
139
  case 0:
@@ -144,9 +148,6 @@ var updateProduct = function (_a) { return __awaiter(void 0, [_a], void 0, funct
144
148
  !salePrice) {
145
149
  throw new Error('Buy price, currency, name, product category ID, quantity, and sale price are required');
146
150
  }
147
- if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
148
- throw new Error('ID mismatch between parameter and queryWhere');
149
- }
150
151
  productData = {
151
152
  buyPrice: buyPrice,
152
153
  currency: currency,
@@ -158,11 +159,18 @@ var updateProduct = function (_a) { return __awaiter(void 0, [_a], void 0, funct
158
159
  ref: ref || null,
159
160
  salePrice: salePrice,
160
161
  };
162
+ include = {
163
+ productCategory: includeProductCategory,
164
+ quotesInvoices: includeQuotesInvoices,
165
+ };
166
+ where = {
167
+ id: id,
168
+ };
161
169
  return [4 /*yield*/, prisma.product.upsert({
162
- include: include || null,
163
- where: __assign({ id: id }, queryWhere),
164
- update: productData,
165
170
  create: __assign({ id: id }, productData),
171
+ include: include,
172
+ update: productData,
173
+ where: where,
166
174
  })];
167
175
  case 1:
168
176
  product = _e.sent();
@@ -177,23 +185,24 @@ exports.updateProduct = updateProduct;
177
185
  * @returns {Promise<ProductBE>} Deleted product
178
186
  */
179
187
  var deleteProduct = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
180
- var product;
181
- var id = _b.id, _c = _b.include, include = _c === void 0 ? {
182
- productCategory: true,
183
- quotesInvoices: true,
184
- } : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
188
+ var include, where, product;
189
+ var id = _b.id, _c = _b.includeProductCategory, includeProductCategory = _c === void 0 ? true : _c, _d = _b.includeQuotesInvoices, includeQuotesInvoices = _d === void 0 ? true : _d, prisma = _b.prisma;
185
190
  return __generator(this, function (_e) {
186
191
  switch (_e.label) {
187
192
  case 0:
188
193
  if (!id) {
189
194
  throw new Error('Product ID is required');
190
195
  }
191
- if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
192
- throw new Error('ID mismatch between parameter and queryWhere');
193
- }
196
+ include = {
197
+ productCategory: includeProductCategory,
198
+ quotesInvoices: includeQuotesInvoices,
199
+ };
200
+ where = {
201
+ id: id,
202
+ };
194
203
  return [4 /*yield*/, prisma.product.delete({
195
- include: include || null,
196
- where: __assign({ id: id }, queryWhere),
204
+ include: include,
205
+ where: where,
197
206
  })];
198
207
  case 1:
199
208
  product = _e.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.24.66",
3
+ "version": "1.24.67",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {