@react-pakistan/util-functions 1.24.64 → 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 +292 -177
  44. package/api/stellar-solutions/type.js +93 -1
  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
package/README.md CHANGED
@@ -54,6 +54,7 @@ A central place to declare all React Web util functions for ReactPakistan eco-sy
54
54
  - Clone the repo
55
55
  - Cd into the project folder
56
56
  - Figure out which package manager you have on your system, then run following commands for their specific use cases.
57
+
57
58
  ```console
58
59
  // to install dependencies
59
60
  yarn
@@ -62,7 +63,9 @@ A central place to declare all React Web util functions for ReactPakistan eco-sy
62
63
  // to run all tests locally
63
64
  yarn test
64
65
  ```
66
+
65
67
  OR
68
+
66
69
  ```console
67
70
  // cd to website directory
68
71
  cd website
@@ -89,8 +92,8 @@ Should you like this project and would like to see more coming in future, please
89
92
 
90
93
  Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
91
94
 
92
- | Contributors | GitHub | Emoji |
93
- | ------------- |:-------------:|:-----:|
95
+ | Contributors | GitHub | Emoji |
96
+ | ------------------------------------------------------------------------- | :-----------------------------------------------------: | :----------: |
94
97
  | <img src="https://avatars0.githubusercontent.com/u/27800340?s=150&v=4" /> | <a href="https://github.com/taimoormk">Taimoor Khan</a> | 🎨🤔🚧📆👀⚠️ |
95
98
 
96
99
  ### 📌 Other Libraries from ReactPakistan 🚀
@@ -338,7 +341,7 @@ I can be reachable via [Taimoor Web](https://taimoor.io) or else should you wish
338
341
  <a
339
342
  href="https://www.buymeacoffee.com/60whp8FM3"
340
343
  target="_blank">
341
- <img
344
+ <img
342
345
  alt="Buy Me A Coffee"
343
346
  src="https://bmc-cdn.nyc3.digitaloceanspaces.com/BMC-button-images/custom_images/yellow_img.png"
344
347
  />
@@ -1,24 +1,73 @@
1
1
  import { AppUserBE } from '../type';
2
- interface GetAppUsersArgs {
3
- prisma: any;
2
+ type PrismaClient = any;
3
+ interface ListAppUserArgs {
4
+ currentPage: number;
5
+ include?: {
6
+ [key: string]: any;
7
+ };
8
+ orderBy?: {
9
+ [key: string]: any;
10
+ };
11
+ pageLimit: number;
12
+ prisma: PrismaClient;
13
+ queryWhere?: {
14
+ [key: string]: any;
15
+ };
4
16
  }
5
- interface GetAppUserByIdArgs {
6
- id: string;
7
- prisma: any;
17
+ interface UnitAppUserByIdArgs {
18
+ include?: {
19
+ [key: string]: any;
20
+ };
21
+ prisma: PrismaClient;
22
+ queryWhere: {
23
+ [key: string]: any;
24
+ };
8
25
  }
9
- interface PostAppUserArgs {
10
- prisma: any;
11
- id: string;
26
+ interface UpdateAppUserArgs {
12
27
  email: string;
13
28
  firstName: string;
29
+ id: string;
30
+ include?: {
31
+ [key: string]: any;
32
+ };
14
33
  lastName: string;
34
+ prisma: PrismaClient;
35
+ queryWhere?: {
36
+ [key: string]: any;
37
+ };
15
38
  }
16
39
  interface DeleteAppUserArgs {
17
- prisma: any;
18
- id: string;
40
+ include?: {
41
+ [key: string]: any;
42
+ };
43
+ prisma: PrismaClient;
44
+ queryWhere: {
45
+ [key: string]: any;
46
+ };
19
47
  }
20
- export declare const getAppUsers: ({ prisma }: GetAppUsersArgs) => Promise<Array<AppUserBE>>;
21
- export declare const getAppUserById: ({ prisma, id }: GetAppUserByIdArgs) => Promise<AppUserBE>;
22
- export declare const postAppUser: ({ prisma, id, email, firstName, lastName, }: PostAppUserArgs) => Promise<Array<AppUserBE>>;
23
- export declare const deleteAppUser: ({ prisma, id }: DeleteAppUserArgs) => Promise<AppUserBE>;
48
+ /**
49
+ * Retrieves all app users from the database with pagination
50
+ * @param {ListAppUserArgs} args - Object containing prisma client, pagination, and query options
51
+ * @returns {Promise<[number, Array<AppUserBE>]>} Tuple of [total count, array of app users]
52
+ */
53
+ export declare const listAppUser: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: ListAppUserArgs) => Promise<[number, Array<AppUserBE>]>;
54
+ /**
55
+ * Retrieves a single app user by ID
56
+ * @param {UnitAppUserByIdArgs} args - Object containing prisma client and user query
57
+ * @returns {Promise<AppUserBE | null>} App user if found, null otherwise
58
+ */
59
+ export declare const unitAppUserById: ({ include, prisma, queryWhere, }: UnitAppUserByIdArgs) => Promise<AppUserBE | null>;
60
+ /**
61
+ * Creates a new app user or updates an existing one
62
+ * @param {UpdateAppUserArgs} args - Object containing prisma client and user data
63
+ * @returns {Promise<AppUserBE>} Created or updated app user
64
+ */
65
+ export declare const updateAppUser: ({ email, firstName, id, include, lastName, prisma, queryWhere, }: UpdateAppUserArgs) => Promise<AppUserBE>;
66
+ /**
67
+ * Deletes an app user by ID
68
+ * @param {DeleteAppUserArgs} args - Object containing prisma client and user query
69
+ * @returns {Promise<AppUserBE>} Deleted app user
70
+ * @throws {Error} If user ID is not provided or user not found
71
+ */
72
+ export declare const deleteAppUser: ({ include, prisma, queryWhere, }: DeleteAppUserArgs) => Promise<AppUserBE>;
24
73
  export {};
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
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,80 +47,124 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
47
  }
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.deleteAppUser = exports.postAppUser = exports.getAppUserById = exports.getAppUsers = void 0;
41
- var getAppUsers = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
50
+ exports.deleteAppUser = exports.updateAppUser = exports.unitAppUserById = exports.listAppUser = void 0;
51
+ /**
52
+ * Retrieves all app users from the database with pagination
53
+ * @param {ListAppUserArgs} args - Object containing prisma client, pagination, and query options
54
+ * @returns {Promise<[number, Array<AppUserBE>]>} Tuple of [total count, array of app users]
55
+ */
56
+ var listAppUser = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
57
  var appUsers;
43
- var prisma = _b.prisma;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0: return [4 /*yield*/, prisma.appUser.findMany({
47
- orderBy: {
48
- createdAt: 'desc',
49
- },
50
- })];
58
+ var currentPage = _b.currentPage, _c = _b.include, include = _c === void 0 ? {} : _c, _d = _b.orderBy, orderBy = _d === void 0 ? { createdAt: 'desc' } : _d, pageLimit = _b.pageLimit, prisma = _b.prisma, _e = _b.queryWhere, queryWhere = _e === void 0 ? {} : _e;
59
+ return __generator(this, function (_f) {
60
+ switch (_f.label) {
61
+ case 0:
62
+ if (!currentPage || currentPage < 1) {
63
+ throw new Error('Valid current page is required');
64
+ }
65
+ if (!pageLimit || pageLimit < 1) {
66
+ throw new Error('Valid page limit is required');
67
+ }
68
+ return [4 /*yield*/, prisma.$transaction([
69
+ prisma.appUser.count({
70
+ where: queryWhere,
71
+ }),
72
+ prisma.appUser.findMany({
73
+ include: include,
74
+ orderBy: orderBy,
75
+ skip: (currentPage - 1) * pageLimit,
76
+ take: pageLimit,
77
+ where: queryWhere,
78
+ }),
79
+ ])];
51
80
  case 1:
52
- appUsers = _c.sent();
81
+ appUsers = _f.sent();
53
82
  return [2 /*return*/, appUsers];
54
83
  }
55
84
  });
56
85
  }); };
57
- exports.getAppUsers = getAppUsers;
58
- var getAppUserById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
86
+ exports.listAppUser = listAppUser;
87
+ /**
88
+ * Retrieves a single app user by ID
89
+ * @param {UnitAppUserByIdArgs} args - Object containing prisma client and user query
90
+ * @returns {Promise<AppUserBE | null>} App user if found, null otherwise
91
+ */
92
+ var unitAppUserById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
59
93
  var appUser;
60
- var prisma = _b.prisma, id = _b.id;
61
- return __generator(this, function (_c) {
62
- switch (_c.label) {
63
- case 0: return [4 /*yield*/, prisma.appUser.findUnique({
64
- where: {
65
- id: id,
66
- },
67
- })];
94
+ var _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, queryWhere = _b.queryWhere;
95
+ return __generator(this, function (_d) {
96
+ switch (_d.label) {
97
+ case 0:
98
+ if (!(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
99
+ throw new Error('User ID is required');
100
+ }
101
+ return [4 /*yield*/, prisma.appUser.findUnique({
102
+ include: include,
103
+ where: queryWhere,
104
+ })];
68
105
  case 1:
69
- appUser = _c.sent();
106
+ appUser = _d.sent();
70
107
  return [2 /*return*/, appUser];
71
108
  }
72
109
  });
73
110
  }); };
74
- exports.getAppUserById = getAppUserById;
75
- var postAppUser = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
76
- var appUser;
77
- var prisma = _b.prisma, id = _b.id, email = _b.email, firstName = _b.firstName, lastName = _b.lastName;
111
+ exports.unitAppUserById = unitAppUserById;
112
+ /**
113
+ * Creates a new app user or updates an existing one
114
+ * @param {UpdateAppUserArgs} args - Object containing prisma client and user data
115
+ * @returns {Promise<AppUserBE>} Created or updated app user
116
+ */
117
+ var updateAppUser = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
118
+ var userData, appUser;
119
+ var email = _b.email, firstName = _b.firstName, id = _b.id, include = _b.include, lastName = _b.lastName, prisma = _b.prisma, queryWhere = _b.queryWhere;
78
120
  return __generator(this, function (_c) {
79
121
  switch (_c.label) {
80
- case 0: return [4 /*yield*/, prisma.appUser.upsert({
81
- where: {
82
- id: id,
83
- },
84
- update: {
85
- email: email,
86
- firstName: firstName,
87
- lastName: lastName,
88
- },
89
- create: {
90
- email: email,
91
- firstName: firstName,
92
- lastName: lastName,
93
- },
94
- })];
122
+ case 0:
123
+ if (!email || !firstName || !lastName) {
124
+ throw new Error('Email, first name, and last name are required');
125
+ }
126
+ if (!id) {
127
+ throw new Error('User ID is required');
128
+ }
129
+ userData = {
130
+ email: email,
131
+ firstName: firstName,
132
+ lastName: lastName,
133
+ };
134
+ return [4 /*yield*/, prisma.appUser.upsert({
135
+ where: queryWhere,
136
+ update: userData,
137
+ create: __assign({ id: id }, userData),
138
+ include: include,
139
+ })];
95
140
  case 1:
96
141
  appUser = _c.sent();
97
142
  return [2 /*return*/, appUser];
98
143
  }
99
144
  });
100
145
  }); };
101
- exports.postAppUser = postAppUser;
146
+ exports.updateAppUser = updateAppUser;
147
+ /**
148
+ * Deletes an app user by ID
149
+ * @param {DeleteAppUserArgs} args - Object containing prisma client and user query
150
+ * @returns {Promise<AppUserBE>} Deleted app user
151
+ * @throws {Error} If user ID is not provided or user not found
152
+ */
102
153
  var deleteAppUser = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
103
154
  var appUser;
104
- var prisma = _b.prisma, id = _b.id;
105
- return __generator(this, function (_c) {
106
- switch (_c.label) {
107
- case 0: return [4 /*yield*/, prisma.appUser.delete({
108
- where: {
109
- id: id,
110
- },
111
- })];
155
+ var _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, queryWhere = _b.queryWhere;
156
+ return __generator(this, function (_d) {
157
+ switch (_d.label) {
158
+ case 0:
159
+ if (!(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
160
+ throw new Error('User ID is required');
161
+ }
162
+ return [4 /*yield*/, prisma.appUser.delete({
163
+ include: include,
164
+ where: queryWhere,
165
+ })];
112
166
  case 1:
113
- appUser = _c.sent();
167
+ appUser = _d.sent();
114
168
  return [2 /*return*/, appUser];
115
169
  }
116
170
  });
@@ -1,30 +1,79 @@
1
1
  import { BankBE } from '../type';
2
- interface GetBanksArgs {
3
- prisma: any;
2
+ type PrismaClient = any;
3
+ interface ListBankArgs {
4
+ currentPage: number;
5
+ include?: {
6
+ [key: string]: any;
7
+ };
8
+ orderBy?: {
9
+ [key: string]: any;
10
+ };
11
+ pageLimit: number;
12
+ prisma: PrismaClient;
13
+ queryWhere?: {
14
+ [key: string]: any;
15
+ };
4
16
  }
5
17
  interface GetBankByIdArgs {
6
- id: string;
7
- prisma: any;
18
+ include?: {
19
+ [key: string]: any;
20
+ };
21
+ prisma: PrismaClient;
22
+ queryWhere: {
23
+ [key: string]: any;
24
+ };
8
25
  }
9
26
  interface PostBankArgs {
10
27
  accountNumber: string;
11
28
  accountTitle: string;
12
- bankAddress: string;
29
+ bankAddress?: string;
13
30
  bankName: string;
14
- createdAt: string;
15
31
  enabled: boolean;
16
- iban: string;
17
- id: string;
32
+ iban?: string;
33
+ id?: string;
34
+ include?: {
35
+ [key: string]: any;
36
+ };
37
+ isDefault?: boolean;
18
38
  preferenceId: string;
19
- prisma: any;
20
- swiftCode: string;
39
+ prisma: PrismaClient;
40
+ queryWhere?: {
41
+ [key: string]: any;
42
+ };
43
+ swiftCode?: string;
21
44
  }
22
45
  interface DeleteBankArgs {
23
- id: string;
24
- prisma: any;
46
+ include?: {
47
+ [key: string]: any;
48
+ };
49
+ prisma: PrismaClient;
50
+ queryWhere: {
51
+ [key: string]: any;
52
+ };
25
53
  }
26
- export declare const getBanks: ({ prisma, }: GetBanksArgs) => Promise<Array<BankBE>>;
27
- export declare const getBankById: ({ prisma, id, }: GetBankByIdArgs) => Promise<BankBE>;
28
- export declare const postBank: ({ prisma, accountNumber, accountTitle, bankAddress, bankName, enabled, iban, id, preferenceId, swiftCode, }: PostBankArgs) => Promise<Array<BankBE>>;
29
- export declare const deleteBank: ({ prisma, id, }: DeleteBankArgs) => Promise<BankBE>;
54
+ /**
55
+ * Retrieves all banks from the database with pagination
56
+ * @param {ListBankArgs} args - Object containing prisma client, pagination, and filter options
57
+ * @returns {Promise<[number, Array<BankBE>]>} Tuple of [total count, array of banks]
58
+ */
59
+ export declare const listBank: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: ListBankArgs) => Promise<[number, Array<BankBE>]>;
60
+ /**
61
+ * Retrieves a single bank by ID
62
+ * @param {GetBankByIdArgs} args - Object containing prisma client and bank id
63
+ * @returns {Promise<BankBE | null>} Bank if found, null otherwise
64
+ */
65
+ export declare const unitBankById: ({ include, prisma, queryWhere, }: GetBankByIdArgs) => Promise<BankBE | null>;
66
+ /**
67
+ * Creates a new bank or updates an existing one
68
+ * @param {PostBankArgs} args - Object containing prisma client and bank data
69
+ * @returns {Promise<BankBE>} Created or updated bank
70
+ */
71
+ export declare const updateBank: ({ accountNumber, accountTitle, bankAddress, bankName, enabled, iban, id, include, isDefault, preferenceId, prisma, queryWhere, swiftCode, }: PostBankArgs) => Promise<BankBE>;
72
+ /**
73
+ * Deletes a bank by ID
74
+ * @param {DeleteBankArgs} args - Object containing prisma client and bank id
75
+ * @returns {Promise<BankBE>} Deleted bank
76
+ * @throws {Error} If bank ID is not provided or bank not found
77
+ */
78
+ export declare const deleteBank: ({ include, prisma, queryWhere, }: DeleteBankArgs) => Promise<BankBE>;
30
79
  export {};
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
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,90 +47,130 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
47
  }
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.deleteBank = exports.postBank = exports.getBankById = exports.getBanks = void 0;
41
- var getBanks = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
50
+ exports.deleteBank = exports.updateBank = exports.unitBankById = exports.listBank = void 0;
51
+ /**
52
+ * Retrieves all banks from the database with pagination
53
+ * @param {ListBankArgs} args - Object containing prisma client, pagination, and filter options
54
+ * @returns {Promise<[number, Array<BankBE>]>} Tuple of [total count, array of banks]
55
+ */
56
+ var listBank = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
57
  var banks;
43
- var prisma = _b.prisma;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0: return [4 /*yield*/, prisma.bank.findMany({
47
- orderBy: {
48
- createdAt: 'desc',
49
- },
50
- })];
58
+ var currentPage = _b.currentPage, _c = _b.include, include = _c === void 0 ? {} : _c, _d = _b.orderBy, orderBy = _d === void 0 ? { createdAt: 'desc' } : _d, pageLimit = _b.pageLimit, prisma = _b.prisma, _e = _b.queryWhere, queryWhere = _e === void 0 ? {} : _e;
59
+ return __generator(this, function (_f) {
60
+ switch (_f.label) {
61
+ case 0:
62
+ if (!currentPage || currentPage < 1) {
63
+ throw new Error('Valid current page is required');
64
+ }
65
+ if (!pageLimit || pageLimit < 1) {
66
+ throw new Error('Valid page limit is required');
67
+ }
68
+ return [4 /*yield*/, prisma.$transaction([
69
+ prisma.bank.count({
70
+ where: queryWhere,
71
+ }),
72
+ prisma.bank.findMany({
73
+ include: include,
74
+ orderBy: orderBy,
75
+ skip: (currentPage - 1) * pageLimit,
76
+ take: pageLimit,
77
+ where: queryWhere,
78
+ }),
79
+ ])];
51
80
  case 1:
52
- banks = _c.sent();
81
+ banks = _f.sent();
53
82
  return [2 /*return*/, banks];
54
83
  }
55
84
  });
56
85
  }); };
57
- exports.getBanks = getBanks;
58
- var getBankById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
86
+ exports.listBank = listBank;
87
+ /**
88
+ * Retrieves a single bank by ID
89
+ * @param {GetBankByIdArgs} args - Object containing prisma client and bank id
90
+ * @returns {Promise<BankBE | null>} Bank if found, null otherwise
91
+ */
92
+ var unitBankById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
59
93
  var bank;
60
- var prisma = _b.prisma, id = _b.id;
61
- return __generator(this, function (_c) {
62
- switch (_c.label) {
63
- case 0: return [4 /*yield*/, prisma.bank.findUnique({
64
- where: {
65
- id: id,
66
- },
67
- })];
94
+ var _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, queryWhere = _b.queryWhere;
95
+ return __generator(this, function (_d) {
96
+ switch (_d.label) {
97
+ case 0:
98
+ if (!(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
99
+ throw new Error('Bank ID is required');
100
+ }
101
+ return [4 /*yield*/, prisma.bank.findUnique({
102
+ include: include,
103
+ where: queryWhere,
104
+ })];
68
105
  case 1:
69
- bank = _c.sent();
106
+ bank = _d.sent();
70
107
  return [2 /*return*/, bank];
71
108
  }
72
109
  });
73
110
  }); };
74
- exports.getBankById = getBankById;
75
- var postBank = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
76
- var bank;
77
- var prisma = _b.prisma, accountNumber = _b.accountNumber, accountTitle = _b.accountTitle, bankAddress = _b.bankAddress, bankName = _b.bankName, enabled = _b.enabled, iban = _b.iban, id = _b.id, preferenceId = _b.preferenceId, swiftCode = _b.swiftCode;
78
- return __generator(this, function (_c) {
79
- switch (_c.label) {
80
- case 0: return [4 /*yield*/, prisma.bank.upsert({
81
- where: {
82
- id: id,
83
- },
84
- update: {
85
- accountNumber: accountNumber,
86
- accountTitle: accountTitle,
87
- bankAddress: bankAddress,
88
- bankName: bankName,
89
- enabled: enabled,
90
- iban: iban,
91
- preferenceId: preferenceId,
92
- swiftCode: swiftCode,
93
- },
94
- create: {
95
- accountNumber: accountNumber,
96
- accountTitle: accountTitle,
97
- bankAddress: bankAddress,
98
- bankName: bankName,
99
- enabled: enabled,
100
- iban: iban,
101
- preferenceId: preferenceId,
102
- swiftCode: swiftCode,
103
- },
104
- })];
111
+ exports.unitBankById = unitBankById;
112
+ /**
113
+ * Creates a new bank or updates an existing one
114
+ * @param {PostBankArgs} args - Object containing prisma client and bank data
115
+ * @returns {Promise<BankBE>} Created or updated bank
116
+ */
117
+ var updateBank = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
118
+ var bankData, bank;
119
+ var accountNumber = _b.accountNumber, accountTitle = _b.accountTitle, bankAddress = _b.bankAddress, bankName = _b.bankName, enabled = _b.enabled, iban = _b.iban, id = _b.id, include = _b.include, _c = _b.isDefault, isDefault = _c === void 0 ? false : _c, preferenceId = _b.preferenceId, prisma = _b.prisma, queryWhere = _b.queryWhere, swiftCode = _b.swiftCode;
120
+ return __generator(this, function (_d) {
121
+ switch (_d.label) {
122
+ case 0:
123
+ if (!accountNumber || !accountTitle || !bankName || !preferenceId) {
124
+ throw new Error('Account number, account title, bank name, and preference ID are required');
125
+ }
126
+ if (!id || !(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
127
+ throw new Error('Bank ID is required');
128
+ }
129
+ bankData = {
130
+ accountNumber: accountNumber,
131
+ accountTitle: accountTitle,
132
+ bankAddress: bankAddress || null,
133
+ bankName: bankName,
134
+ enabled: enabled,
135
+ iban: iban || null,
136
+ isDefault: isDefault,
137
+ preferenceId: preferenceId,
138
+ swiftCode: swiftCode || null,
139
+ };
140
+ return [4 /*yield*/, prisma.bank.upsert({
141
+ where: queryWhere,
142
+ update: bankData,
143
+ create: __assign({ id: id }, bankData),
144
+ include: include,
145
+ })];
105
146
  case 1:
106
- bank = _c.sent();
147
+ bank = _d.sent();
107
148
  return [2 /*return*/, bank];
108
149
  }
109
150
  });
110
151
  }); };
111
- exports.postBank = postBank;
152
+ exports.updateBank = updateBank;
153
+ /**
154
+ * Deletes a bank by ID
155
+ * @param {DeleteBankArgs} args - Object containing prisma client and bank id
156
+ * @returns {Promise<BankBE>} Deleted bank
157
+ * @throws {Error} If bank ID is not provided or bank not found
158
+ */
112
159
  var deleteBank = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
113
160
  var bank;
114
- var prisma = _b.prisma, id = _b.id;
115
- return __generator(this, function (_c) {
116
- switch (_c.label) {
117
- case 0: return [4 /*yield*/, prisma.bank.delete({
118
- where: {
119
- id: id,
120
- },
121
- })];
161
+ var _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, queryWhere = _b.queryWhere;
162
+ return __generator(this, function (_d) {
163
+ switch (_d.label) {
164
+ case 0:
165
+ if (!(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
166
+ throw new Error('Bank ID is required');
167
+ }
168
+ return [4 /*yield*/, prisma.bank.delete({
169
+ include: include,
170
+ where: queryWhere,
171
+ })];
122
172
  case 1:
123
- bank = _c.sent();
173
+ bank = _d.sent();
124
174
  return [2 /*return*/, bank];
125
175
  }
126
176
  });