@react-pakistan/util-functions 1.24.67 → 1.24.68

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 (41) hide show
  1. package/api/stellar-solutions/app-user/index.d.ts +8 -31
  2. package/api/stellar-solutions/app-user/index.js +26 -24
  3. package/api/stellar-solutions/bank/index.d.ts +9 -32
  4. package/api/stellar-solutions/bank/index.js +19 -25
  5. package/api/stellar-solutions/branch/index.d.ts +9 -32
  6. package/api/stellar-solutions/branch/index.js +19 -25
  7. package/api/stellar-solutions/company/index.d.ts +9 -32
  8. package/api/stellar-solutions/company/index.js +29 -27
  9. package/api/stellar-solutions/company-report/index.d.ts +5 -12
  10. package/api/stellar-solutions/company-report/index.js +23 -16
  11. package/api/stellar-solutions/contact/index.d.ts +8 -31
  12. package/api/stellar-solutions/contact/index.js +19 -25
  13. package/api/stellar-solutions/currency/index.d.ts +8 -31
  14. package/api/stellar-solutions/currency/index.js +30 -27
  15. package/api/stellar-solutions/customer/index.d.ts +9 -35
  16. package/api/stellar-solutions/customer/index.js +31 -30
  17. package/api/stellar-solutions/expense/index.d.ts +11 -32
  18. package/api/stellar-solutions/expense/index.js +41 -50
  19. package/api/stellar-solutions/expense-category/index.d.ts +13 -34
  20. package/api/stellar-solutions/expense-category/index.js +64 -52
  21. package/api/stellar-solutions/lead/index.d.ts +35 -19
  22. package/api/stellar-solutions/lead/index.js +117 -82
  23. package/api/stellar-solutions/menu-order/index.d.ts +19 -15
  24. package/api/stellar-solutions/menu-order/index.js +43 -33
  25. package/api/stellar-solutions/payment/index.d.ts +30 -47
  26. package/api/stellar-solutions/payment/index.js +64 -65
  27. package/api/stellar-solutions/payment-mode/index.d.ts +6 -13
  28. package/api/stellar-solutions/payment-mode/index.js +28 -46
  29. package/api/stellar-solutions/preference/index.d.ts +11 -9
  30. package/api/stellar-solutions/preference/index.js +30 -37
  31. package/api/stellar-solutions/product-category/index.d.ts +10 -13
  32. package/api/stellar-solutions/product-category/index.js +58 -49
  33. package/api/stellar-solutions/profile/index.d.ts +6 -5
  34. package/api/stellar-solutions/profile/index.js +17 -18
  35. package/api/stellar-solutions/quote-invoice/index.d.ts +41 -31
  36. package/api/stellar-solutions/quote-invoice/index.js +116 -124
  37. package/api/stellar-solutions/quote-invoice-report/index.d.ts +7 -14
  38. package/api/stellar-solutions/quote-invoice-report/index.js +27 -20
  39. package/api/stellar-solutions/tax/index.d.ts +11 -18
  40. package/api/stellar-solutions/tax/index.js +49 -40
  41. package/package.json +1 -1
@@ -1,15 +1,4 @@
1
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
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -55,7 +44,8 @@ exports.deletePaymentMode = exports.updatePaymentMode = exports.unitPaymentModeB
55
44
  */
56
45
  var listPaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
46
  var skip, _c, count, data;
58
- var _d = _b.currentPage, currentPage = _d === void 0 ? 1 : _d, _e = _b.include, include = _e === void 0 ? {} : _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;
47
+ var _d;
48
+ var _e = _b.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _b.orderByColumn, orderByColumn = _f === void 0 ? 'createdAt' : _f, _g = _b.orderByDirection, orderByDirection = _g === void 0 ? 'desc' : _g, _h = _b.pageLimit, pageLimit = _h === void 0 ? 10 : _h, prisma = _b.prisma;
59
49
  return __generator(this, function (_j) {
60
50
  switch (_j.label) {
61
51
  case 0:
@@ -66,16 +56,14 @@ var listPaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, fun
66
56
  throw new Error('Page limit must be greater than or equal to 1');
67
57
  }
68
58
  skip = (currentPage - 1) * pageLimit;
69
- return [4 /*yield*/, Promise.all([
70
- prisma.paymentMode.count({
71
- where: queryWhere,
72
- }),
59
+ return [4 /*yield*/, prisma.$transaction([
60
+ prisma.paymentMode.count(),
73
61
  prisma.paymentMode.findMany({
74
- include: include || null,
75
- orderBy: orderBy,
62
+ orderBy: (_d = {},
63
+ _d[orderByColumn] = orderByDirection,
64
+ _d),
76
65
  skip: skip,
77
66
  take: pageLimit,
78
- where: queryWhere,
79
67
  }),
80
68
  ])];
81
69
  case 1:
@@ -92,22 +80,20 @@ exports.listPaymentMode = listPaymentMode;
92
80
  */
93
81
  var unitPaymentModeById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
94
82
  var paymentMode;
95
- var id = _b.id, _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
96
- return __generator(this, function (_e) {
97
- switch (_e.label) {
83
+ var id = _b.id, prisma = _b.prisma;
84
+ return __generator(this, function (_c) {
85
+ switch (_c.label) {
98
86
  case 0:
99
87
  if (!id) {
100
88
  throw new Error('Payment mode ID is required');
101
89
  }
102
- if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
103
- throw new Error('ID mismatch between parameter and queryWhere');
104
- }
105
90
  return [4 /*yield*/, prisma.paymentMode.findUnique({
106
- include: include || null,
107
- where: __assign({ id: id }, queryWhere),
91
+ where: {
92
+ id: id,
93
+ },
108
94
  })];
109
95
  case 1:
110
- paymentMode = _e.sent();
96
+ paymentMode = _c.sent();
111
97
  return [2 /*return*/, paymentMode];
112
98
  }
113
99
  });
@@ -120,9 +106,9 @@ exports.unitPaymentModeById = unitPaymentModeById;
120
106
  */
121
107
  var updatePaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
122
108
  var paymentMode;
123
- var enabled = _b.enabled, id = _b.id, _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
124
- return __generator(this, function (_e) {
125
- switch (_e.label) {
109
+ var enabled = _b.enabled, id = _b.id, prisma = _b.prisma;
110
+ return __generator(this, function (_c) {
111
+ switch (_c.label) {
126
112
  case 0:
127
113
  if (!id) {
128
114
  throw new Error('Payment mode ID is required');
@@ -130,18 +116,16 @@ var updatePaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, f
130
116
  if (typeof enabled !== 'boolean') {
131
117
  throw new Error('Enabled status must be a boolean');
132
118
  }
133
- if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
134
- throw new Error('ID mismatch between parameter and queryWhere');
135
- }
136
119
  return [4 /*yield*/, prisma.paymentMode.update({
137
- include: include || null,
138
- where: __assign({ id: id }, queryWhere),
120
+ where: {
121
+ id: id,
122
+ },
139
123
  data: {
140
124
  enabled: enabled,
141
125
  },
142
126
  })];
143
127
  case 1:
144
- paymentMode = _e.sent();
128
+ paymentMode = _c.sent();
145
129
  return [2 /*return*/, paymentMode];
146
130
  }
147
131
  });
@@ -154,22 +138,20 @@ exports.updatePaymentMode = updatePaymentMode;
154
138
  */
155
139
  var deletePaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
156
140
  var paymentMode;
157
- var id = _b.id, _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
158
- return __generator(this, function (_e) {
159
- switch (_e.label) {
141
+ var id = _b.id, prisma = _b.prisma;
142
+ return __generator(this, function (_c) {
143
+ switch (_c.label) {
160
144
  case 0:
161
145
  if (!id) {
162
146
  throw new Error('Payment mode ID is required');
163
147
  }
164
- if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
165
- throw new Error('ID mismatch between parameter and queryWhere');
166
- }
167
148
  return [4 /*yield*/, prisma.paymentMode.delete({
168
- include: include || null,
169
- where: __assign({ id: id }, queryWhere),
149
+ where: {
150
+ id: id,
151
+ },
170
152
  })];
171
153
  case 1:
172
- paymentMode = _e.sent();
154
+ paymentMode = _c.sent();
173
155
  return [2 /*return*/, paymentMode];
174
156
  }
175
157
  });
@@ -1,23 +1,25 @@
1
1
  import { PreferenceBE } from '../type';
2
2
  type PrismaClient = any;
3
3
  interface GetPreferencesArgs {
4
+ orderByColumn?: string;
5
+ orderByDirection?: 'asc' | 'desc';
4
6
  prisma: PrismaClient;
5
7
  }
6
8
  interface PostPreferenceArgs {
7
- id?: string;
9
+ id: string;
8
10
  onboarding: boolean;
9
11
  prisma: PrismaClient;
10
12
  }
11
13
  /**
12
- * Retrieves all preferences with related data
13
- * @param {GetPreferencesArgs} args - Object containing prisma client
14
- * @returns {Promise<Array<PreferenceBE>>} Array of preferences with related entities (banks, branches, currencies, etc.)
14
+ * Retrieves all preferences
15
+ * @param {GetPreferencesArgs} args - Object containing prisma client and ordering options
16
+ * @returns {Promise<Array<PreferenceBE>>} Array of preferences
15
17
  */
16
- export declare const getPreferences: ({ prisma, }: GetPreferencesArgs) => Promise<Array<PreferenceBE>>;
18
+ export declare const getPreferences: ({ orderByColumn, orderByDirection, prisma, }: GetPreferencesArgs) => Promise<Array<PreferenceBE>>;
17
19
  /**
18
- * Creates a new preference or updates an existing one
19
- * @param {PostPreferenceArgs} args - Object containing prisma client, optional preference ID, and onboarding status
20
- * @returns {Promise<PreferenceBE>} Created or updated preference
20
+ * Updates a preference using upsert
21
+ * @param {PostPreferenceArgs} args - Object containing prisma client, preference ID, and onboarding status
22
+ * @returns {Promise<PreferenceBE>} Updated preference
21
23
  */
22
- export declare const postPreference: ({ prisma, id, onboarding, }: PostPreferenceArgs) => Promise<PreferenceBE>;
24
+ export declare const postPreference: ({ id, onboarding, prisma, }: PostPreferenceArgs) => Promise<PreferenceBE>;
23
25
  export {};
@@ -49,67 +49,60 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
50
  exports.postPreference = exports.getPreferences = void 0;
51
51
  /**
52
- * Retrieves all preferences with related data
53
- * @param {GetPreferencesArgs} args - Object containing prisma client
54
- * @returns {Promise<Array<PreferenceBE>>} Array of preferences with related entities (banks, branches, currencies, etc.)
52
+ * Retrieves all preferences
53
+ * @param {GetPreferencesArgs} args - Object containing prisma client and ordering options
54
+ * @returns {Promise<Array<PreferenceBE>>} Array of preferences
55
55
  */
56
56
  var getPreferences = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var preferences;
58
- var prisma = _b.prisma;
59
- return __generator(this, function (_c) {
60
- switch (_c.label) {
61
- case 0: return [4 /*yield*/, prisma.preference.findMany({
62
- orderBy: {
63
- createdAt: 'desc',
64
- },
65
- include: {
66
- banks: true,
67
- branches: true,
68
- currencies: true,
69
- menuOrder: true,
70
- paymentModes: true,
71
- taxes: true,
72
- },
73
- })];
57
+ var include, orderBy, where, preferences;
58
+ var _c;
59
+ var _d = _b.orderByColumn, orderByColumn = _d === void 0 ? 'createdAt' : _d, _e = _b.orderByDirection, orderByDirection = _e === void 0 ? 'desc' : _e, prisma = _b.prisma;
60
+ return __generator(this, function (_f) {
61
+ switch (_f.label) {
62
+ case 0:
63
+ include = {};
64
+ orderBy = (_c = {},
65
+ _c[orderByColumn] = orderByDirection,
66
+ _c);
67
+ where = {};
68
+ return [4 /*yield*/, prisma.preference.findMany({
69
+ include: include,
70
+ orderBy: orderBy,
71
+ where: where,
72
+ })];
74
73
  case 1:
75
- preferences = _c.sent();
74
+ preferences = _f.sent();
76
75
  return [2 /*return*/, preferences];
77
76
  }
78
77
  });
79
78
  }); };
80
79
  exports.getPreferences = getPreferences;
81
80
  /**
82
- * Creates a new preference or updates an existing one
83
- * @param {PostPreferenceArgs} args - Object containing prisma client, optional preference ID, and onboarding status
84
- * @returns {Promise<PreferenceBE>} Created or updated preference
81
+ * Updates a preference using upsert
82
+ * @param {PostPreferenceArgs} args - Object containing prisma client, preference ID, and onboarding status
83
+ * @returns {Promise<PreferenceBE>} Updated preference
85
84
  */
86
85
  var postPreference = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
87
- var preferenceData, preference_1, preference;
88
- var prisma = _b.prisma, id = _b.id, onboarding = _b.onboarding;
86
+ var preferenceData, preference;
87
+ var id = _b.id, onboarding = _b.onboarding, prisma = _b.prisma;
89
88
  return __generator(this, function (_c) {
90
89
  switch (_c.label) {
91
90
  case 0:
91
+ if (!id) {
92
+ throw new Error('Preference ID is required');
93
+ }
92
94
  if (typeof onboarding !== 'boolean') {
93
95
  throw new Error('Onboarding status must be a boolean');
94
96
  }
95
97
  preferenceData = {
96
98
  onboarding: onboarding,
97
99
  };
98
- if (!id) return [3 /*break*/, 2];
99
100
  return [4 /*yield*/, prisma.preference.upsert({
100
- where: {
101
- id: id,
102
- },
103
- update: preferenceData,
104
101
  create: __assign({ id: id }, preferenceData),
102
+ update: preferenceData,
103
+ where: { id: id },
105
104
  })];
106
105
  case 1:
107
- preference_1 = _c.sent();
108
- return [2 /*return*/, preference_1];
109
- case 2: return [4 /*yield*/, prisma.preference.create({
110
- data: preferenceData,
111
- })];
112
- case 3:
113
106
  preference = _c.sent();
114
107
  return [2 /*return*/, preference];
115
108
  }
@@ -2,54 +2,51 @@ import { ProductCategoryBE } from '../type';
2
2
  type PrismaClient = any;
3
3
  interface ListProductCategoryArgs {
4
4
  currentPage?: number;
5
- include?: any;
6
- orderBy?: any;
5
+ includeProducts?: boolean;
6
+ orderByColumn?: string;
7
+ orderByDirection?: 'asc' | 'desc';
7
8
  pageLimit?: number;
8
9
  prisma: PrismaClient;
9
- queryWhere?: any;
10
10
  }
11
11
  interface UnitProductCategoryByIdArgs {
12
12
  id: string;
13
- include?: any;
13
+ includeProducts?: boolean;
14
14
  prisma: PrismaClient;
15
- queryWhere?: any;
16
15
  }
17
16
  interface UpdateProductCategoryArgs {
18
17
  description?: string;
19
18
  id: string;
20
- include?: any;
19
+ includeProducts?: boolean;
21
20
  name: string;
22
21
  prisma: PrismaClient;
23
- queryWhere?: any;
24
22
  }
25
23
  interface DeleteProductCategoryArgs {
26
24
  id: string;
27
- include?: any;
25
+ includeProducts?: boolean;
28
26
  prisma: PrismaClient;
29
- queryWhere?: any;
30
27
  }
31
28
  /**
32
29
  * Retrieves a paginated list of product categories
33
30
  * @param {ListProductCategoryArgs} args - Object containing prisma client, pagination, filtering, and ordering options
34
31
  * @returns {Promise<[number, Array<ProductCategoryBE>]>} Tuple containing total count and array of product categories
35
32
  */
36
- export declare const listProductCategory: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: ListProductCategoryArgs) => Promise<[number, Array<ProductCategoryBE>]>;
33
+ export declare const listProductCategory: ({ currentPage, includeProducts, orderByColumn, orderByDirection, pageLimit, prisma, }: ListProductCategoryArgs) => Promise<[number, Array<ProductCategoryBE>]>;
37
34
  /**
38
35
  * Retrieves a single product category by its ID
39
36
  * @param {UnitProductCategoryByIdArgs} args - Object containing prisma client, product category ID, and optional query parameters
40
37
  * @returns {Promise<ProductCategoryBE | null>} Product category or null if not found
41
38
  */
42
- export declare const unitProductCategoryById: ({ id, include, prisma, queryWhere, }: UnitProductCategoryByIdArgs) => Promise<ProductCategoryBE | null>;
39
+ export declare const unitProductCategoryById: ({ id, includeProducts, prisma, }: UnitProductCategoryByIdArgs) => Promise<ProductCategoryBE | null>;
43
40
  /**
44
41
  * Creates or updates a product category
45
42
  * @param {UpdateProductCategoryArgs} args - Object containing prisma client, product category data, and optional query parameters
46
43
  * @returns {Promise<ProductCategoryBE>} Created or updated product category
47
44
  */
48
- export declare const updateProductCategory: ({ description, id, include, name, prisma, queryWhere, }: UpdateProductCategoryArgs) => Promise<ProductCategoryBE>;
45
+ export declare const updateProductCategory: ({ description, id, includeProducts, name, prisma, }: UpdateProductCategoryArgs) => Promise<ProductCategoryBE>;
49
46
  /**
50
47
  * Deletes a product category by ID
51
48
  * @param {DeleteProductCategoryArgs} args - Object containing prisma client, product category ID, and optional query parameters
52
49
  * @returns {Promise<ProductCategoryBE>} Deleted product category
53
50
  */
54
- export declare const deleteProductCategory: ({ id, include, prisma, queryWhere, }: DeleteProductCategoryArgs) => Promise<ProductCategoryBE>;
51
+ export declare const deleteProductCategory: ({ id, includeProducts, prisma, }: DeleteProductCategoryArgs) => Promise<ProductCategoryBE>;
55
52
  export {};
@@ -54,12 +54,11 @@ exports.deleteProductCategory = exports.updateProductCategory = exports.unitProd
54
54
  * @returns {Promise<[number, Array<ProductCategoryBE>]>} Tuple containing total count and array of product categories
55
55
  */
56
56
  var listProductCategory = 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
- products: true,
60
- } : _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;
61
- return __generator(this, function (_j) {
62
- 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.includeProducts, includeProducts = _f === void 0 ? false : _f, _g = _b.orderByColumn, orderByColumn = _g === void 0 ? 'createdAt' : _g, _h = _b.orderByDirection, orderByDirection = _h === void 0 ? 'desc' : _h, _j = _b.pageLimit, pageLimit = _j === void 0 ? 10 : _j, prisma = _b.prisma;
60
+ return __generator(this, function (_k) {
61
+ switch (_k.label) {
63
62
  case 0:
64
63
  if (currentPage < 1) {
65
64
  throw new Error('Current page must be greater than or equal to 1');
@@ -67,22 +66,29 @@ var listProductCategory = function (_a) { return __awaiter(void 0, [_a], void 0,
67
66
  if (pageLimit < 1) {
68
67
  throw new Error('Page limit must be greater than or equal to 1');
69
68
  }
69
+ include = {
70
+ products: includeProducts,
71
+ };
72
+ orderBy = (_d = {},
73
+ _d[orderByColumn] = orderByDirection,
74
+ _d);
70
75
  skip = (currentPage - 1) * pageLimit;
71
- return [4 /*yield*/, Promise.all([
76
+ where = {};
77
+ return [4 /*yield*/, prisma.$transaction([
72
78
  prisma.productCategory.count({
73
- where: queryWhere,
79
+ where: where,
74
80
  }),
75
81
  prisma.productCategory.findMany({
76
- include: include || null,
82
+ include: include,
77
83
  orderBy: orderBy,
78
84
  skip: skip,
79
85
  take: pageLimit,
80
- where: queryWhere,
86
+ where: where,
81
87
  }),
82
88
  ])];
83
89
  case 1:
84
- _c = _j.sent(), count = _c[0], data = _c[1];
85
- return [2 /*return*/, [count, data]];
90
+ _c = _k.sent(), count = _c[0], items = _c[1];
91
+ return [2 /*return*/, [count, items]];
86
92
  }
87
93
  });
88
94
  }); };
@@ -93,25 +99,26 @@ exports.listProductCategory = listProductCategory;
93
99
  * @returns {Promise<ProductCategoryBE | null>} Product category or null if not found
94
100
  */
95
101
  var unitProductCategoryById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
96
- var productCategory;
97
- var id = _b.id, _c = _b.include, include = _c === void 0 ? {
98
- products: true,
99
- } : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
100
- return __generator(this, function (_e) {
101
- switch (_e.label) {
102
+ var include, where, productCategory;
103
+ var id = _b.id, _c = _b.includeProducts, includeProducts = _c === void 0 ? false : _c, prisma = _b.prisma;
104
+ return __generator(this, function (_d) {
105
+ switch (_d.label) {
102
106
  case 0:
103
107
  if (!id) {
104
108
  throw new Error('Product category ID is required');
105
109
  }
106
- if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
107
- throw new Error('ID mismatch between parameter and queryWhere');
108
- }
110
+ include = {
111
+ products: includeProducts,
112
+ };
113
+ where = {
114
+ id: id,
115
+ };
109
116
  return [4 /*yield*/, prisma.productCategory.findUnique({
110
- include: include || null,
111
- where: __assign({ id: id }, queryWhere),
117
+ include: include,
118
+ where: where,
112
119
  })];
113
120
  case 1:
114
- productCategory = _e.sent();
121
+ productCategory = _d.sent();
115
122
  return [2 /*return*/, productCategory];
116
123
  }
117
124
  });
@@ -123,12 +130,10 @@ exports.unitProductCategoryById = unitProductCategoryById;
123
130
  * @returns {Promise<ProductCategoryBE>} Created or updated product category
124
131
  */
125
132
  var updateProductCategory = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
126
- var productCategoryData, productCategory;
127
- var description = _b.description, id = _b.id, _c = _b.include, include = _c === void 0 ? {
128
- products: true,
129
- } : _c, name = _b.name, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
130
- return __generator(this, function (_e) {
131
- switch (_e.label) {
133
+ var productCategoryData, include, where, productCategory;
134
+ var description = _b.description, id = _b.id, _c = _b.includeProducts, includeProducts = _c === void 0 ? true : _c, name = _b.name, prisma = _b.prisma;
135
+ return __generator(this, function (_d) {
136
+ switch (_d.label) {
132
137
  case 0:
133
138
  if (!id) {
134
139
  throw new Error('Product category ID is required');
@@ -136,21 +141,24 @@ var updateProductCategory = function (_a) { return __awaiter(void 0, [_a], void
136
141
  if (!name) {
137
142
  throw new Error('Product category name is required');
138
143
  }
139
- if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
140
- throw new Error('ID mismatch between parameter and queryWhere');
141
- }
142
144
  productCategoryData = {
143
145
  description: description || null,
144
146
  name: name,
145
147
  };
148
+ include = {
149
+ products: includeProducts,
150
+ };
151
+ where = {
152
+ id: id,
153
+ };
146
154
  return [4 /*yield*/, prisma.productCategory.upsert({
147
- include: include || null,
148
- where: __assign({ id: id }, queryWhere),
149
- update: productCategoryData,
150
155
  create: __assign({ id: id }, productCategoryData),
156
+ include: include,
157
+ update: productCategoryData,
158
+ where: where,
151
159
  })];
152
160
  case 1:
153
- productCategory = _e.sent();
161
+ productCategory = _d.sent();
154
162
  return [2 /*return*/, productCategory];
155
163
  }
156
164
  });
@@ -162,25 +170,26 @@ exports.updateProductCategory = updateProductCategory;
162
170
  * @returns {Promise<ProductCategoryBE>} Deleted product category
163
171
  */
164
172
  var deleteProductCategory = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
165
- var productCategory;
166
- var id = _b.id, _c = _b.include, include = _c === void 0 ? {
167
- products: true,
168
- } : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
169
- return __generator(this, function (_e) {
170
- switch (_e.label) {
173
+ var include, where, productCategory;
174
+ var id = _b.id, _c = _b.includeProducts, includeProducts = _c === void 0 ? true : _c, prisma = _b.prisma;
175
+ return __generator(this, function (_d) {
176
+ switch (_d.label) {
171
177
  case 0:
172
178
  if (!id) {
173
179
  throw new Error('Product category ID is required');
174
180
  }
175
- if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
176
- throw new Error('ID mismatch between parameter and queryWhere');
177
- }
181
+ include = {
182
+ products: includeProducts,
183
+ };
184
+ where = {
185
+ id: id,
186
+ };
178
187
  return [4 /*yield*/, prisma.productCategory.delete({
179
- include: include || null,
180
- where: __assign({ id: id }, queryWhere),
188
+ include: include,
189
+ where: where,
181
190
  })];
182
191
  case 1:
183
- productCategory = _e.sent();
192
+ productCategory = _d.sent();
184
193
  return [2 /*return*/, productCategory];
185
194
  }
186
195
  });
@@ -1,6 +1,8 @@
1
1
  import { ProfileBE } from '../type';
2
2
  type PrismaClient = any;
3
3
  interface GetProfilesArgs {
4
+ orderByColumn?: string;
5
+ orderByDirection?: 'asc' | 'desc';
4
6
  prisma: PrismaClient;
5
7
  }
6
8
  interface GetProfileByIdArgs {
@@ -13,11 +15,10 @@ interface GetProfileByUserIdArgs {
13
15
  }
14
16
  interface PostProfilesArgs {
15
17
  currentPage: number;
18
+ orderByColumn?: string;
19
+ orderByDirection?: 'asc' | 'desc';
16
20
  pageLimit: number;
17
21
  prisma: PrismaClient;
18
- queryWhere?: {
19
- [key: string]: any;
20
- };
21
22
  }
22
23
  interface PostProfileArgs {
23
24
  avatar?: string;
@@ -43,7 +44,7 @@ interface DeleteProfileArgs {
43
44
  * @param {GetProfilesArgs} args - Object containing prisma client
44
45
  * @returns {Promise<Array<ProfileBE>>} Array of profiles ordered by creation date (newest first)
45
46
  */
46
- export declare const getProfiles: ({ prisma, }: GetProfilesArgs) => Promise<Array<ProfileBE>>;
47
+ export declare const getProfiles: ({ orderByColumn, orderByDirection, prisma, }: GetProfilesArgs) => Promise<Array<ProfileBE>>;
47
48
  /**
48
49
  * Retrieves a profile by its ID
49
50
  * @param {GetProfileByIdArgs} args - Object containing prisma client and profile ID
@@ -61,7 +62,7 @@ export declare const getProfileByUserId: ({ prisma, userId, }: GetProfileByUserI
61
62
  * @param {PostProfilesArgs} args - Object containing prisma client, pagination, and filtering options
62
63
  * @returns {Promise<[number, Array<ProfileBE>]>} Tuple of [total count, profiles array]
63
64
  */
64
- export declare const postProfiles: ({ currentPage, pageLimit, prisma, queryWhere, }: PostProfilesArgs) => Promise<[number, Array<ProfileBE>]>;
65
+ export declare const postProfiles: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, }: PostProfilesArgs) => Promise<[number, Array<ProfileBE>]>;
65
66
  /**
66
67
  * Creates a new profile or updates an existing one
67
68
  * @param {PostProfileArgs} args - Object containing prisma client and profile data
@@ -55,16 +55,17 @@ exports.deleteProfile = exports.postProfile = exports.postProfiles = exports.get
55
55
  */
56
56
  var getProfiles = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
57
  var profiles;
58
- var prisma = _b.prisma;
59
- return __generator(this, function (_c) {
60
- switch (_c.label) {
58
+ var _c;
59
+ var _d = _b.orderByColumn, orderByColumn = _d === void 0 ? 'createdAt' : _d, _e = _b.orderByDirection, orderByDirection = _e === void 0 ? 'desc' : _e, prisma = _b.prisma;
60
+ return __generator(this, function (_f) {
61
+ switch (_f.label) {
61
62
  case 0: return [4 /*yield*/, prisma.profile.findMany({
62
- orderBy: {
63
- createdAt: 'desc',
64
- },
63
+ orderBy: (_c = {},
64
+ _c[orderByColumn] = orderByDirection,
65
+ _c),
65
66
  })];
66
67
  case 1:
67
- profiles = _c.sent();
68
+ profiles = _f.sent();
68
69
  return [2 /*return*/, profiles];
69
70
  }
70
71
  });
@@ -129,9 +130,10 @@ exports.getProfileByUserId = getProfileByUserId;
129
130
  */
130
131
  var postProfiles = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
131
132
  var profiles;
132
- var _c = _b.currentPage, currentPage = _c === void 0 ? 1 : _c, _d = _b.pageLimit, pageLimit = _d === void 0 ? 10 : _d, prisma = _b.prisma, _e = _b.queryWhere, queryWhere = _e === void 0 ? {} : _e;
133
- return __generator(this, function (_f) {
134
- switch (_f.label) {
133
+ var _c;
134
+ var _d = _b.currentPage, currentPage = _d === void 0 ? 1 : _d, _e = _b.orderByColumn, orderByColumn = _e === void 0 ? 'createdAt' : _e, _f = _b.orderByDirection, orderByDirection = _f === void 0 ? 'desc' : _f, _g = _b.pageLimit, pageLimit = _g === void 0 ? 10 : _g, prisma = _b.prisma;
135
+ return __generator(this, function (_h) {
136
+ switch (_h.label) {
135
137
  case 0:
136
138
  if (currentPage < 1) {
137
139
  throw new Error('Current page must be greater than 0');
@@ -140,20 +142,17 @@ var postProfiles = function (_a) { return __awaiter(void 0, [_a], void 0, functi
140
142
  throw new Error('Page limit must be greater than 0');
141
143
  }
142
144
  return [4 /*yield*/, prisma.$transaction([
143
- prisma.profile.count({
144
- where: queryWhere,
145
- }),
145
+ prisma.profile.count(),
146
146
  prisma.profile.findMany({
147
- orderBy: {
148
- createdAt: 'desc',
149
- },
150
- where: queryWhere,
147
+ orderBy: (_c = {},
148
+ _c[orderByColumn] = orderByDirection,
149
+ _c),
151
150
  take: pageLimit,
152
151
  skip: (currentPage - 1) * pageLimit,
153
152
  }),
154
153
  ])];
155
154
  case 1:
156
- profiles = _f.sent();
155
+ profiles = _h.sent();
157
156
  return [2 /*return*/, profiles];
158
157
  }
159
158
  });