@react-pakistan/util-functions 1.24.65 → 1.24.66

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 (110) hide show
  1. package/README.md +6 -3
  2. package/api/stellar-solutions/app-user/index.d.ts +63 -14
  3. package/api/stellar-solutions/app-user/index.js +106 -52
  4. package/api/stellar-solutions/bank/index.d.ts +65 -16
  5. package/api/stellar-solutions/bank/index.js +115 -65
  6. package/api/stellar-solutions/branch/index.d.ts +64 -15
  7. package/api/stellar-solutions/branch/index.js +119 -65
  8. package/api/stellar-solutions/company/index.d.ts +58 -24
  9. package/api/stellar-solutions/company/index.js +106 -78
  10. package/api/stellar-solutions/company-report/index.d.ts +12 -5
  11. package/api/stellar-solutions/company-report/index.js +12 -7
  12. package/api/stellar-solutions/contact/index.d.ts +54 -20
  13. package/api/stellar-solutions/contact/index.js +109 -88
  14. package/api/stellar-solutions/currency/index.d.ts +63 -14
  15. package/api/stellar-solutions/currency/index.js +113 -61
  16. package/api/stellar-solutions/customer/index.d.ts +70 -28
  17. package/api/stellar-solutions/customer/index.js +131 -101
  18. package/api/stellar-solutions/expense/index.d.ts +58 -22
  19. package/api/stellar-solutions/expense/index.js +128 -92
  20. package/api/stellar-solutions/expense-category/index.d.ts +58 -22
  21. package/api/stellar-solutions/expense-category/index.js +125 -86
  22. package/api/stellar-solutions/lead/index.js +0 -1
  23. package/api/stellar-solutions/menu-order/index.d.ts +29 -7
  24. package/api/stellar-solutions/menu-order/index.js +74 -27
  25. package/api/stellar-solutions/payment/index.d.ts +62 -27
  26. package/api/stellar-solutions/payment/index.js +144 -123
  27. package/api/stellar-solutions/payment-mode/index.d.ts +44 -12
  28. package/api/stellar-solutions/payment-mode/index.js +115 -49
  29. package/api/stellar-solutions/preference/index.d.ts +14 -3
  30. package/api/stellar-solutions/preference/index.js +44 -14
  31. package/api/stellar-solutions/product/index.d.ts +46 -31
  32. package/api/stellar-solutions/product/index.js +142 -113
  33. package/api/stellar-solutions/product-category/index.d.ts +44 -27
  34. package/api/stellar-solutions/product-category/index.js +123 -87
  35. package/api/stellar-solutions/profile/index.d.ts +48 -17
  36. package/api/stellar-solutions/profile/index.js +124 -65
  37. package/api/stellar-solutions/quote-invoice/index.d.ts +67 -8
  38. package/api/stellar-solutions/quote-invoice/index.js +123 -57
  39. package/api/stellar-solutions/quote-invoice-report/index.d.ts +12 -5
  40. package/api/stellar-solutions/quote-invoice-report/index.js +10 -5
  41. package/api/stellar-solutions/tax/index.d.ts +46 -14
  42. package/api/stellar-solutions/tax/index.js +135 -63
  43. package/api/stellar-solutions/type.d.ts +178 -112
  44. package/api/stellar-solutions/type.js +60 -2
  45. package/constants/countries-timezones.js +0 -1
  46. package/constants/currencies.js +0 -1
  47. package/general/basic-get.js +22 -21
  48. package/general/basic-post.js +19 -18
  49. package/general/calculate-pages.js +3 -1
  50. package/general/check-even-odd-length.js +3 -2
  51. package/general/delete-image-from-private-supabase.js +0 -1
  52. package/general/delete-image-from-public-supabase.js +0 -1
  53. package/general/dynamic-page-limit.js +3 -2
  54. package/general/enum-to-text.js +7 -4
  55. package/general/fetch-data.js +0 -1
  56. package/general/fetch-supabase-image.js +0 -1
  57. package/general/fetch-supabase-private-assets.js +15 -14
  58. package/general/format-date.js +8 -8
  59. package/general/format-number.js +3 -2
  60. package/general/format-time.js +3 -2
  61. package/general/full-year-range.js +2 -2
  62. package/general/generate-blog-schema.d.ts +3 -3
  63. package/general/generate-blog-schema.js +20 -13
  64. package/general/generate-breadcrumb-schema.d.ts +4 -4
  65. package/general/generate-breadcrumb-schema.js +9 -10
  66. package/general/generate-faq-schema.d.ts +5 -5
  67. package/general/generate-faq-schema.js +18 -11
  68. package/general/generate-grid.js +0 -1
  69. package/general/generate-organization-schema.d.ts +3 -3
  70. package/general/generate-organization-schema.js +25 -18
  71. package/general/get-available-page-limit.js +2 -2
  72. package/general/get-calendar-dates.js +14 -3
  73. package/general/get-full-name.d.ts +1 -1
  74. package/general/get-number-of-days-in-month.d.ts +1 -1
  75. package/general/get-pathname.js +4 -1
  76. package/general/is-odd.js +1 -1
  77. package/general/is-previous-button-disabled.js +3 -1
  78. package/general/parse-frontmatter.js +0 -1
  79. package/general/remove-data-image-prefix.js +3 -2
  80. package/general/repeat-times.js +0 -1
  81. package/general/resolve-current-date.js +1 -2
  82. package/general/resolve-grid.js +3 -2
  83. package/general/slugify.js +11 -9
  84. package/general/text-to-enum.js +6 -1
  85. package/general/text-to-sentence-case.js +3 -1
  86. package/general/time-out.js +5 -4
  87. package/general/truncate-text.js +3 -1
  88. package/general/upload-blob-to-private-supabase.js +2 -2
  89. package/general/upload-blob-to-public-supabase.js +2 -2
  90. package/general/upload-image-to-private-supabase.js +2 -2
  91. package/general/upload-image-to-public-supabase.js +2 -2
  92. package/general/validate-email.js +1 -1
  93. package/hooks/use-fetch.js +11 -12
  94. package/hooks/use-module-entity.js +5 -6
  95. package/hooks/use-sticky.js +0 -1
  96. package/hooks/with-seo.d.ts +1 -1
  97. package/hooks/with-seo.js +3 -4
  98. package/local-storage/get-storage-value.js +0 -1
  99. package/package.json +22 -13
  100. package/setupTests.js +1 -2
  101. package/storybook/generate-sitemap.js +0 -1
  102. package/storybook/preview.js +1 -4
  103. package/storybook/react-design-story-script.js +0 -2
  104. package/storybook/react-emoji-collection.js +8 -6
  105. package/storybook/react-emoji-story-script.js +0 -2
  106. package/storybook/react-icon-collection.js +4 -3
  107. package/storybook/react-icon-story-script.js +0 -2
  108. package/storybook/react-logo-collection.js +4 -3
  109. package/storybook/react-logo-story-script.js +0 -2
  110. package/storybook/responsive-component.js +14 -7
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any, no-restricted-globals */
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
+ };
3
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,127 +47,127 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
47
  }
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.deletePayment = exports.postPayment = exports.postPayments = exports.getPaymentById = exports.getPayments = void 0;
41
- var getPayments = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var payments;
43
- var prisma = _b.prisma;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0: return [4 /*yield*/, prisma.payment.findMany({
47
- orderBy: {
48
- createdAt: 'desc',
49
- },
50
- })];
50
+ exports.deletePayment = exports.updatePayment = exports.unitPaymentById = exports.listPayment = void 0;
51
+ /**
52
+ * Retrieves payments with pagination and filtering
53
+ * @param {ListPaymentArgs} args - Object containing prisma client, pagination, and query options
54
+ * @returns {Promise<[number, Array<PaymentBE>]>} Tuple containing total count and array of payments
55
+ */
56
+ var listPayment = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
+ var _c, count, payments;
58
+ var currentPage = _b.currentPage, _d = _b.include, include = _d === void 0 ? {} : _d, _e = _b.orderBy, orderBy = _e === void 0 ? { createdAt: 'desc' } : _e, pageLimit = _b.pageLimit, prisma = _b.prisma, _f = _b.queryWhere, queryWhere = _f === void 0 ? {} : _f;
59
+ return __generator(this, function (_g) {
60
+ switch (_g.label) {
61
+ case 0:
62
+ if (currentPage < 1) {
63
+ throw new Error('Current page must be greater than or equal to 1');
64
+ }
65
+ if (pageLimit < 1) {
66
+ throw new Error('Page limit must be greater than or equal to 1');
67
+ }
68
+ return [4 /*yield*/, prisma.$transaction([
69
+ prisma.payment.count({
70
+ where: queryWhere,
71
+ }),
72
+ prisma.payment.findMany({
73
+ orderBy: orderBy,
74
+ include: include,
75
+ where: queryWhere,
76
+ take: pageLimit,
77
+ skip: (currentPage - 1) * pageLimit,
78
+ }),
79
+ ])];
51
80
  case 1:
52
- payments = _c.sent();
53
- return [2 /*return*/, payments];
81
+ _c = _g.sent(), count = _c[0], payments = _c[1];
82
+ return [2 /*return*/, [count, payments]];
54
83
  }
55
84
  });
56
85
  }); };
57
- exports.getPayments = getPayments;
58
- var getPaymentById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
86
+ exports.listPayment = listPayment;
87
+ /**
88
+ * Retrieves a single payment by ID
89
+ * @param {UnitPaymentByIdArgs} args - Object containing prisma client, payment id, and optional query parameters
90
+ * @returns {Promise<PaymentBE | null>} Payment with optional relations if found, null otherwise
91
+ */
92
+ var unitPaymentById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
59
93
  var payment;
60
- var id = _b.id, prisma = _b.prisma;
61
- return __generator(this, function (_c) {
62
- switch (_c.label) {
63
- case 0: return [4 /*yield*/, prisma.payment.findUnique({
64
- where: {
65
- id: id,
66
- },
67
- })];
94
+ var id = _b.id, _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
95
+ return __generator(this, function (_e) {
96
+ switch (_e.label) {
97
+ case 0:
98
+ if (!id) {
99
+ throw new Error('Payment ID is required');
100
+ }
101
+ if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
102
+ throw new Error('ID mismatch between parameter and queryWhere');
103
+ }
104
+ return [4 /*yield*/, prisma.payment.findUnique({
105
+ where: __assign({ id: id }, queryWhere),
106
+ include: include || undefined,
107
+ })];
68
108
  case 1:
69
- payment = _c.sent();
109
+ payment = _e.sent();
70
110
  return [2 /*return*/, payment];
71
111
  }
72
112
  });
73
113
  }); };
74
- exports.getPaymentById = getPaymentById;
75
- var postPayments = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
76
- var payments;
77
- var currentPage = _b.currentPage, include = _b.include, orderBy = _b.orderBy, pageLimit = _b.pageLimit, prisma = _b.prisma, queryWhere = _b.queryWhere;
78
- return __generator(this, function (_c) {
79
- switch (_c.label) {
80
- case 0: return [4 /*yield*/, prisma.$transaction([
81
- prisma.payment.count({
82
- where: queryWhere,
83
- }),
84
- prisma.payment.findMany({
85
- orderBy: orderBy,
86
- include: include,
87
- where: queryWhere,
88
- take: pageLimit,
89
- skip: (currentPage - 1) * pageLimit,
90
- }),
91
- ])];
92
- case 1:
93
- payments = _c.sent();
94
- return [2 /*return*/, payments];
95
- }
96
- });
97
- }); };
98
- exports.postPayments = postPayments;
99
- var postPayment = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
100
- var invoice, allPaymentsForInvoice, calculateBalance, payment;
101
- var amount = _b.amount, attachment = _b.attachment, currency = _b.currency, date = _b.date, description = _b.description, id = _b.id, mode = _b.mode, paymentType = _b.paymentType, prisma = _b.prisma, quoteInvoiceId = _b.quoteInvoiceId, ref = _b.ref;
102
- return __generator(this, function (_c) {
103
- switch (_c.label) {
104
- case 0: return [4 /*yield*/, prisma.quoteInvoice.findUnique({
105
- where: {
106
- id: quoteInvoiceId,
107
- },
108
- })];
109
- case 1:
110
- invoice = _c.sent();
111
- return [4 /*yield*/, prisma.payment.findMany({
112
- where: {
113
- quoteInvoiceId: quoteInvoiceId,
114
- },
115
- include: {
116
- quoteInvoice: true,
117
- },
118
- })];
119
- case 2:
120
- allPaymentsForInvoice = _c.sent();
121
- calculateBalance = function () {
122
- if (paymentType === 'PARTIAL_AMOUNT') {
123
- return allPaymentsForInvoice && invoice.total - Number(amount) - allPaymentsForInvoice
124
- .reduce(function (acc, _a) {
125
- var paymentAmount = _a.amount;
126
- return acc + paymentAmount;
127
- }, 0);
128
- }
129
- return 0;
114
+ exports.unitPaymentById = unitPaymentById;
115
+ /**
116
+ * Creates or updates a payment using upsert
117
+ * @param {UpdatePaymentArgs} args - Object containing prisma client and payment data
118
+ * @returns {Promise<PaymentBE>} Created or updated payment
119
+ */
120
+ var updatePayment = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
121
+ var paymentData, paymentId, payment;
122
+ var amount = _b.amount, attachment = _b.attachment, balance = _b.balance, currency = _b.currency, date = _b.date, description = _b.description, id = _b.id, _c = _b.include, include = _c === void 0 ? {} : _c, paymentModeId = _b.paymentModeId, paymentType = _b.paymentType, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d, quoteInvoiceId = _b.quoteInvoiceId, ref = _b.ref;
123
+ return __generator(this, function (_e) {
124
+ switch (_e.label) {
125
+ case 0:
126
+ if (!amount ||
127
+ !currency ||
128
+ !date ||
129
+ !paymentModeId ||
130
+ !paymentType ||
131
+ !quoteInvoiceId) {
132
+ throw new Error('Amount, currency, date, payment mode ID, payment type, and quote invoice ID are required');
133
+ }
134
+ if (id && (queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
135
+ throw new Error('ID mismatch between parameter and queryWhere');
136
+ }
137
+ paymentData = {
138
+ amount: amount,
139
+ attachment: attachment || null,
140
+ balance: balance,
141
+ currency: currency,
142
+ date: date,
143
+ description: description || null,
144
+ paymentModeId: paymentModeId,
145
+ paymentType: paymentType,
146
+ quoteInvoiceId: quoteInvoiceId,
147
+ ref: ref || null,
130
148
  };
131
- return [4 /*yield*/, prisma.payment.upsert({
132
- where: {
133
- id: id,
134
- },
135
- update: {
136
- amount: amount,
137
- attachment: attachment,
138
- date: date,
139
- description: description,
140
- mode: mode,
141
- paymentType: paymentType,
142
- quoteInvoiceId: quoteInvoiceId,
143
- ref: ref,
144
- },
145
- create: {
146
- amount: amount,
147
- attachment: attachment,
148
- balance: String(calculateBalance()),
149
- currency: currency,
150
- date: date,
151
- description: description,
152
- mode: mode,
153
- paymentType: paymentType,
154
- quoteInvoiceId: quoteInvoiceId,
155
- ref: ref,
156
- },
149
+ paymentId = id || (queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id);
150
+ if (!!paymentId) return [3 /*break*/, 2];
151
+ return [4 /*yield*/, prisma.payment.create({
152
+ data: paymentData,
153
+ include: include || undefined,
157
154
  })];
155
+ case 1:
156
+ // Create new payment without specific ID
157
+ payment = _e.sent();
158
+ return [3 /*break*/, 4];
159
+ case 2: return [4 /*yield*/, prisma.payment.upsert({
160
+ where: __assign({ id: paymentId }, queryWhere),
161
+ update: paymentData,
162
+ create: __assign({ id: paymentId }, paymentData),
163
+ include: include || undefined,
164
+ })];
158
165
  case 3:
159
- payment = _c.sent();
160
- if (!(calculateBalance() === 0)) return [3 /*break*/, 5];
166
+ // Upsert with provided ID
167
+ payment = _e.sent();
168
+ _e.label = 4;
169
+ case 4:
170
+ if (!(Number(balance) === 0)) return [3 /*break*/, 6];
161
171
  return [4 /*yield*/, prisma.quoteInvoice.update({
162
172
  where: {
163
173
  id: quoteInvoiceId,
@@ -166,26 +176,37 @@ var postPayment = function (_a) { return __awaiter(void 0, [_a], void 0, functio
166
176
  invoiceStatus: 'PAID',
167
177
  },
168
178
  })];
169
- case 4:
170
- _c.sent();
171
- _c.label = 5;
172
- case 5: return [2 /*return*/, payment];
179
+ case 5:
180
+ _e.sent();
181
+ _e.label = 6;
182
+ case 6: return [2 /*return*/, payment];
173
183
  }
174
184
  });
175
185
  }); };
176
- exports.postPayment = postPayment;
186
+ exports.updatePayment = updatePayment;
187
+ /**
188
+ * Deletes a payment by ID
189
+ * @param {DeletePaymentArgs} args - Object containing prisma client, payment ID, and optional query parameters
190
+ * @returns {Promise<PaymentBE>} Deleted payment
191
+ */
177
192
  var deletePayment = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
178
193
  var payment;
179
- var id = _b.id, prisma = _b.prisma;
180
- return __generator(this, function (_c) {
181
- switch (_c.label) {
182
- case 0: return [4 /*yield*/, prisma.payment.delete({
183
- where: {
184
- id: id,
185
- },
186
- })];
194
+ var id = _b.id, _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
195
+ return __generator(this, function (_e) {
196
+ switch (_e.label) {
197
+ case 0:
198
+ if (!id) {
199
+ throw new Error('Payment ID is required');
200
+ }
201
+ if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
202
+ throw new Error('ID mismatch between parameter and queryWhere');
203
+ }
204
+ return [4 /*yield*/, prisma.payment.delete({
205
+ where: __assign({ id: id }, queryWhere),
206
+ include: include || undefined,
207
+ })];
187
208
  case 1:
188
- payment = _c.sent();
209
+ payment = _e.sent();
189
210
  return [2 /*return*/, payment];
190
211
  }
191
212
  });
@@ -1,22 +1,54 @@
1
1
  import { PaymentModeBE } from '../type';
2
- interface GetPaymentModesArgs {
3
- prisma: any;
2
+ type PrismaClient = any;
3
+ interface ListPaymentModeArgs {
4
+ currentPage?: number;
5
+ include?: any;
6
+ orderBy?: any;
7
+ pageLimit?: number;
8
+ prisma: PrismaClient;
9
+ queryWhere?: any;
4
10
  }
5
- interface GetPaymentModeByIdArgs {
11
+ interface UnitPaymentModeByIdArgs {
6
12
  id: string;
7
- prisma: any;
13
+ include?: any;
14
+ prisma: PrismaClient;
15
+ queryWhere?: any;
8
16
  }
9
- interface PostPaymentModeArgs {
10
- enabled: string;
17
+ interface UpdatePaymentModeArgs {
18
+ enabled: boolean;
11
19
  id: string;
12
- prisma: any;
20
+ include?: any;
21
+ prisma: PrismaClient;
22
+ queryWhere?: any;
13
23
  }
14
24
  interface DeletePaymentModeArgs {
15
25
  id: string;
16
- prisma: any;
26
+ include?: any;
27
+ prisma: PrismaClient;
28
+ queryWhere?: any;
17
29
  }
18
- export declare const getPaymentModes: ({ prisma, }: GetPaymentModesArgs) => Promise<Array<PaymentModeBE>>;
19
- export declare const getPaymentModeById: ({ id, prisma, }: GetPaymentModeByIdArgs) => Promise<PaymentModeBE>;
20
- export declare const postPaymentMode: ({ enabled, id, prisma, }: PostPaymentModeArgs) => Promise<Array<PaymentModeBE>>;
21
- export declare const deletePaymentMode: ({ id, prisma, }: DeletePaymentModeArgs) => Promise<PaymentModeBE>;
30
+ /**
31
+ * Retrieves a paginated list of payment modes
32
+ * @param {ListPaymentModeArgs} args - Object containing prisma client, pagination, filtering, and ordering options
33
+ * @returns {Promise<[number, Array<PaymentModeBE>]>} Tuple containing total count and array of payment modes
34
+ */
35
+ export declare const listPaymentMode: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: ListPaymentModeArgs) => Promise<[number, Array<PaymentModeBE>]>;
36
+ /**
37
+ * Retrieves a single payment mode by its ID
38
+ * @param {UnitPaymentModeByIdArgs} args - Object containing prisma client, payment mode ID, and optional query parameters
39
+ * @returns {Promise<PaymentModeBE | null>} Payment mode or null if not found
40
+ */
41
+ export declare const unitPaymentModeById: ({ id, include, prisma, queryWhere, }: UnitPaymentModeByIdArgs) => Promise<PaymentModeBE | null>;
42
+ /**
43
+ * Updates a payment mode's enabled status
44
+ * @param {UpdatePaymentModeArgs} args - Object containing prisma client, payment mode ID, enabled status, and optional query parameters
45
+ * @returns {Promise<PaymentModeBE>} Updated payment mode
46
+ */
47
+ export declare const updatePaymentMode: ({ enabled, id, include, prisma, queryWhere, }: UpdatePaymentModeArgs) => Promise<PaymentModeBE>;
48
+ /**
49
+ * Deletes a payment mode by ID
50
+ * @param {DeletePaymentModeArgs} args - Object containing prisma client, payment mode ID, and optional query parameters
51
+ * @returns {Promise<PaymentModeBE>} Deleted payment mode
52
+ */
53
+ export declare const deletePaymentMode: ({ id, include, prisma, queryWhere, }: DeletePaymentModeArgs) => Promise<PaymentModeBE>;
22
54
  export {};
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any, no-restricted-globals */
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
+ };
3
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,73 +47,129 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
47
  }
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.deletePaymentMode = exports.postPaymentMode = exports.getPaymentModeById = exports.getPaymentModes = void 0;
41
- var getPaymentModes = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var paymentModes;
43
- var prisma = _b.prisma;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0: return [4 /*yield*/, prisma.paymentMode.findMany({
47
- orderBy: {
48
- createdAt: 'desc',
49
- },
50
- })];
50
+ exports.deletePaymentMode = exports.updatePaymentMode = exports.unitPaymentModeById = exports.listPaymentMode = void 0;
51
+ /**
52
+ * Retrieves a paginated list of payment modes
53
+ * @param {ListPaymentModeArgs} args - Object containing prisma client, pagination, filtering, and ordering options
54
+ * @returns {Promise<[number, Array<PaymentModeBE>]>} Tuple containing total count and array of payment modes
55
+ */
56
+ var listPaymentMode = 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 ? {} : _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;
59
+ return __generator(this, function (_j) {
60
+ switch (_j.label) {
61
+ case 0:
62
+ if (currentPage < 1) {
63
+ throw new Error('Current page must be greater than or equal to 1');
64
+ }
65
+ if (pageLimit < 1) {
66
+ throw new Error('Page limit must be greater than or equal to 1');
67
+ }
68
+ skip = (currentPage - 1) * pageLimit;
69
+ return [4 /*yield*/, Promise.all([
70
+ prisma.paymentMode.count({
71
+ where: queryWhere,
72
+ }),
73
+ prisma.paymentMode.findMany({
74
+ include: include || null,
75
+ orderBy: orderBy,
76
+ skip: skip,
77
+ take: pageLimit,
78
+ where: queryWhere,
79
+ }),
80
+ ])];
51
81
  case 1:
52
- paymentModes = _c.sent();
53
- return [2 /*return*/, paymentModes];
82
+ _c = _j.sent(), count = _c[0], data = _c[1];
83
+ return [2 /*return*/, [count, data]];
54
84
  }
55
85
  });
56
86
  }); };
57
- exports.getPaymentModes = getPaymentModes;
58
- var getPaymentModeById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
87
+ exports.listPaymentMode = listPaymentMode;
88
+ /**
89
+ * Retrieves a single payment mode by its ID
90
+ * @param {UnitPaymentModeByIdArgs} args - Object containing prisma client, payment mode ID, and optional query parameters
91
+ * @returns {Promise<PaymentModeBE | null>} Payment mode or null if not found
92
+ */
93
+ var unitPaymentModeById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
59
94
  var paymentMode;
60
- var id = _b.id, prisma = _b.prisma;
61
- return __generator(this, function (_c) {
62
- switch (_c.label) {
63
- case 0: return [4 /*yield*/, prisma.paymentMode.findUnique({
64
- where: {
65
- id: id,
66
- },
67
- })];
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) {
98
+ case 0:
99
+ if (!id) {
100
+ throw new Error('Payment mode ID is required');
101
+ }
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
+ return [4 /*yield*/, prisma.paymentMode.findUnique({
106
+ include: include || null,
107
+ where: __assign({ id: id }, queryWhere),
108
+ })];
68
109
  case 1:
69
- paymentMode = _c.sent();
110
+ paymentMode = _e.sent();
70
111
  return [2 /*return*/, paymentMode];
71
112
  }
72
113
  });
73
114
  }); };
74
- exports.getPaymentModeById = getPaymentModeById;
75
- var postPaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
115
+ exports.unitPaymentModeById = unitPaymentModeById;
116
+ /**
117
+ * Updates a payment mode's enabled status
118
+ * @param {UpdatePaymentModeArgs} args - Object containing prisma client, payment mode ID, enabled status, and optional query parameters
119
+ * @returns {Promise<PaymentModeBE>} Updated payment mode
120
+ */
121
+ var updatePaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
76
122
  var paymentMode;
77
- var enabled = _b.enabled, id = _b.id, prisma = _b.prisma;
78
- return __generator(this, function (_c) {
79
- switch (_c.label) {
80
- case 0: return [4 /*yield*/, prisma.paymentMode.update({
81
- where: {
82
- id: id,
83
- },
84
- data: {
85
- enabled: enabled,
86
- },
87
- })];
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) {
126
+ case 0:
127
+ if (!id) {
128
+ throw new Error('Payment mode ID is required');
129
+ }
130
+ if (typeof enabled !== 'boolean') {
131
+ throw new Error('Enabled status must be a boolean');
132
+ }
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
+ return [4 /*yield*/, prisma.paymentMode.update({
137
+ include: include || null,
138
+ where: __assign({ id: id }, queryWhere),
139
+ data: {
140
+ enabled: enabled,
141
+ },
142
+ })];
88
143
  case 1:
89
- paymentMode = _c.sent();
144
+ paymentMode = _e.sent();
90
145
  return [2 /*return*/, paymentMode];
91
146
  }
92
147
  });
93
148
  }); };
94
- exports.postPaymentMode = postPaymentMode;
149
+ exports.updatePaymentMode = updatePaymentMode;
150
+ /**
151
+ * Deletes a payment mode by ID
152
+ * @param {DeletePaymentModeArgs} args - Object containing prisma client, payment mode ID, and optional query parameters
153
+ * @returns {Promise<PaymentModeBE>} Deleted payment mode
154
+ */
95
155
  var deletePaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
96
156
  var paymentMode;
97
- var id = _b.id, prisma = _b.prisma;
98
- return __generator(this, function (_c) {
99
- switch (_c.label) {
100
- case 0: return [4 /*yield*/, prisma.paymentMode.delete({
101
- where: {
102
- id: id,
103
- },
104
- })];
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) {
160
+ case 0:
161
+ if (!id) {
162
+ throw new Error('Payment mode ID is required');
163
+ }
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
+ return [4 /*yield*/, prisma.paymentMode.delete({
168
+ include: include || null,
169
+ where: __assign({ id: id }, queryWhere),
170
+ })];
105
171
  case 1:
106
- paymentMode = _c.sent();
172
+ paymentMode = _e.sent();
107
173
  return [2 /*return*/, paymentMode];
108
174
  }
109
175
  });
@@ -1,12 +1,23 @@
1
1
  import { PreferenceBE } from '../type';
2
+ type PrismaClient = any;
2
3
  interface GetPreferencesArgs {
3
- prisma: any;
4
+ prisma: PrismaClient;
4
5
  }
5
6
  interface PostPreferenceArgs {
6
- id: string;
7
+ id?: string;
7
8
  onboarding: boolean;
8
- prisma: any;
9
+ prisma: PrismaClient;
9
10
  }
11
+ /**
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.)
15
+ */
10
16
  export declare const getPreferences: ({ prisma, }: GetPreferencesArgs) => Promise<Array<PreferenceBE>>;
17
+ /**
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
21
+ */
11
22
  export declare const postPreference: ({ prisma, id, onboarding, }: PostPreferenceArgs) => Promise<PreferenceBE>;
12
23
  export {};