@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
@@ -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,84 +47,126 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
47
  }
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.deleteCurrency = exports.postCurrency = exports.getCurrencyById = exports.getCurrencies = void 0;
41
- var getCurrencies = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var customers;
43
- var prisma = _b.prisma;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0: return [4 /*yield*/, prisma.currency.findMany({
47
- orderBy: {
48
- createdAt: 'desc',
49
- },
50
- })];
50
+ exports.deleteCurrency = exports.updateCurrency = exports.unitCurrencyById = exports.listCurrency = void 0;
51
+ /**
52
+ * Retrieves currencies with pagination and filtering
53
+ * @param {ListCurrencyArgs} args - Object containing prisma client, pagination, and query options
54
+ * @returns {Promise<[number, Array<CurrencyBE>]>} Tuple containing total count and array of currencies
55
+ */
56
+ var listCurrency = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
+ var _c, count, currencies;
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('Valid current page is required');
64
+ }
65
+ if (pageLimit < 1) {
66
+ throw new Error('Valid page limit is required');
67
+ }
68
+ return [4 /*yield*/, prisma.$transaction([
69
+ prisma.currency.count({
70
+ where: queryWhere,
71
+ }),
72
+ prisma.currency.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
- customers = _c.sent();
53
- return [2 /*return*/, customers];
81
+ _c = _g.sent(), count = _c[0], currencies = _c[1];
82
+ return [2 /*return*/, [count, currencies]];
54
83
  }
55
84
  });
56
85
  }); };
57
- exports.getCurrencies = getCurrencies;
58
- var getCurrencyById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
86
+ exports.listCurrency = listCurrency;
87
+ /**
88
+ * Retrieves a single currency by ID
89
+ * @param {UnitCurrencyByIdArgs} args - Object containing prisma client and query where conditions
90
+ * @returns {Promise<CurrencyBE | null>} Currency if found, null otherwise
91
+ */
92
+ var unitCurrencyById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
59
93
  var currency;
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.currency.findUnique({
64
- where: {
65
- id: id,
66
- },
67
- })];
94
+ var prisma = _b.prisma, queryWhere = _b.queryWhere, _c = _b.include, include = _c === void 0 ? {} : _c;
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('Currency ID is required');
100
+ }
101
+ return [4 /*yield*/, prisma.currency.findUnique({
102
+ include: include,
103
+ where: queryWhere,
104
+ })];
68
105
  case 1:
69
- currency = _c.sent();
106
+ currency = _d.sent();
70
107
  return [2 /*return*/, currency];
71
108
  }
72
109
  });
73
110
  }); };
74
- exports.getCurrencyById = getCurrencyById;
75
- var postCurrency = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
76
- var currency;
77
- var code = _b.code, enabled = _b.enabled, id = _b.id, isDefault = _b.isDefault, label = _b.label, preferenceId = _b.preferenceId, prisma = _b.prisma;
78
- return __generator(this, function (_c) {
79
- switch (_c.label) {
80
- case 0: return [4 /*yield*/, prisma.currency.upsert({
81
- where: {
82
- id: id,
83
- },
84
- update: {
85
- code: code,
86
- enabled: enabled,
87
- isDefault: isDefault,
88
- label: label,
89
- preferenceId: preferenceId,
90
- },
91
- create: {
92
- code: code,
93
- enabled: enabled,
94
- isDefault: isDefault,
95
- label: label,
96
- preferenceId: preferenceId,
97
- },
98
- })];
111
+ exports.unitCurrencyById = unitCurrencyById;
112
+ /**
113
+ * Creates or updates a currency
114
+ * @param {UpdateCurrencyArgs} args - Object containing prisma client and currency data
115
+ * @returns {Promise<CurrencyBE>} Created or updated currency
116
+ */
117
+ var updateCurrency = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
118
+ var currencyData, currency;
119
+ var code = _b.code, enabled = _b.enabled, id = _b.id, _c = _b.isDefault, isDefault = _c === void 0 ? false : _c, label = _b.label, preferenceId = _b.preferenceId, prisma = _b.prisma, queryWhere = _b.queryWhere, include = _b.include;
120
+ return __generator(this, function (_d) {
121
+ switch (_d.label) {
122
+ case 0:
123
+ if (!id || !(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
124
+ throw new Error('Currency ID is required');
125
+ }
126
+ if (!code || !label || !preferenceId) {
127
+ throw new Error('Code, label, and preference ID are required');
128
+ }
129
+ currencyData = {
130
+ code: code,
131
+ enabled: enabled,
132
+ isDefault: isDefault,
133
+ label: label,
134
+ preferenceId: preferenceId,
135
+ };
136
+ return [4 /*yield*/, prisma.currency.upsert({
137
+ where: queryWhere,
138
+ update: currencyData,
139
+ create: __assign({ id: id }, currencyData),
140
+ include: include,
141
+ })];
99
142
  case 1:
100
- currency = _c.sent();
143
+ currency = _d.sent();
101
144
  return [2 /*return*/, currency];
102
145
  }
103
146
  });
104
147
  }); };
105
- exports.postCurrency = postCurrency;
148
+ exports.updateCurrency = updateCurrency;
149
+ /**
150
+ * Deletes a currency by ID
151
+ * @param {DeleteCurrencyArgs} args - Object containing prisma client and query where conditions
152
+ * @returns {Promise<CurrencyBE>} Deleted currency
153
+ * @throws {Error} If currency ID is not provided or currency not found
154
+ */
106
155
  var deleteCurrency = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
107
156
  var currency;
108
- var id = _b.id, prisma = _b.prisma;
109
- return __generator(this, function (_c) {
110
- switch (_c.label) {
111
- case 0: return [4 /*yield*/, prisma.currency.delete({
112
- where: {
113
- id: id,
114
- },
115
- })];
157
+ var prisma = _b.prisma, queryWhere = _b.queryWhere, _c = _b.include, include = _c === void 0 ? {} : _c;
158
+ return __generator(this, function (_d) {
159
+ switch (_d.label) {
160
+ case 0:
161
+ if (!(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
162
+ throw new Error('Currency ID is required');
163
+ }
164
+ return [4 /*yield*/, prisma.currency.delete({
165
+ include: include,
166
+ where: queryWhere,
167
+ })];
116
168
  case 1:
117
- currency = _c.sent();
169
+ currency = _d.sent();
118
170
  return [2 /*return*/, currency];
119
171
  }
120
172
  });
@@ -1,48 +1,90 @@
1
1
  import { CustomerBE } from '../type';
2
- interface GetCustomersArgs {
3
- prisma: any;
4
- }
5
- interface GetCustomerByIdArgs {
6
- id: string;
7
- prisma: any;
8
- }
9
- interface GetCustomerByPhoneArgs {
10
- phone: string;
11
- prisma: any;
12
- }
13
- interface PostCustomersArgs {
2
+ type PrismaClient = any;
3
+ interface ListCustomerArgs {
14
4
  currentPage: number;
15
- include: {
5
+ include?: {
16
6
  [key: string]: any;
17
7
  };
18
- orderBy: {
8
+ orderBy?: {
19
9
  [key: string]: any;
20
10
  };
21
11
  pageLimit: number;
22
- prisma: any;
12
+ prisma: PrismaClient;
13
+ queryWhere?: {
14
+ [key: string]: any;
15
+ };
16
+ }
17
+ interface UnitCustomerByIdArgs {
18
+ include?: {
19
+ [key: string]: any;
20
+ };
21
+ prisma: PrismaClient;
23
22
  queryWhere: {
24
23
  [key: string]: any;
25
24
  };
26
25
  }
27
- interface PostCustomerArgs {
28
- prisma: any;
29
- id: string;
30
- address: string;
26
+ interface UnitCustomerByPhoneArgs {
27
+ include?: {
28
+ [key: string]: any;
29
+ };
30
+ phone: string;
31
+ prisma: PrismaClient;
32
+ }
33
+ interface UpdateCustomerArgs {
34
+ address?: string;
31
35
  city: string;
32
36
  country: string;
33
- email: string;
37
+ email?: string;
34
38
  firstName: string;
39
+ id: string;
40
+ include?: {
41
+ [key: string]: any;
42
+ };
35
43
  lastName: string;
36
44
  phone: string;
45
+ prisma: PrismaClient;
46
+ queryWhere: {
47
+ [key: string]: any;
48
+ };
37
49
  }
38
50
  interface DeleteCustomerArgs {
39
- prisma: any;
40
- id: string;
51
+ include?: {
52
+ [key: string]: any;
53
+ };
54
+ prisma: PrismaClient;
55
+ queryWhere: {
56
+ [key: string]: any;
57
+ };
41
58
  }
42
- export declare const getCustomers: ({ prisma, }: GetCustomersArgs) => Promise<Array<CustomerBE>>;
43
- export declare const getCustomerById: ({ prisma, id, }: GetCustomerByIdArgs) => Promise<CustomerBE>;
44
- export declare const getCustomerByPhone: ({ prisma, phone }: GetCustomerByPhoneArgs) => Promise<CustomerBE>;
45
- export declare const postCustomers: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: PostCustomersArgs) => Promise<Array<CustomerBE>>;
46
- export declare const postCustomer: ({ prisma, id, address, city, country, email, firstName, lastName, phone, }: PostCustomerArgs) => Promise<Array<CustomerBE>>;
47
- export declare const deleteCustomer: ({ prisma, id }: DeleteCustomerArgs) => Promise<CustomerBE>;
59
+ /**
60
+ * Retrieves customers with pagination and filtering
61
+ * @param {ListCustomerArgs} args - Object containing prisma client, pagination, and query options
62
+ * @returns {Promise<[number, Array<CustomerBE>]>} Tuple containing total count and array of customers
63
+ */
64
+ export declare const listCustomer: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: ListCustomerArgs) => Promise<[number, Array<CustomerBE>]>;
65
+ /**
66
+ * Retrieves a single customer by ID
67
+ * @param {UnitCustomerByIdArgs} args - Object containing prisma client and query where conditions
68
+ * @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
69
+ */
70
+ export declare const unitCustomerById: ({ prisma, queryWhere, include, }: UnitCustomerByIdArgs) => Promise<CustomerBE | null>;
71
+ /**
72
+ * Retrieves a single customer by phone number
73
+ * @param {UnitCustomerByPhoneArgs} args - Object containing prisma client and phone number
74
+ * @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
75
+ */
76
+ export declare const unitCustomerByPhone: ({ prisma, phone, include, }: UnitCustomerByPhoneArgs) => Promise<CustomerBE | null>;
77
+ /**
78
+ * Creates or updates a customer
79
+ * @param {UpdateCustomerArgs} args - Object containing prisma client and customer data
80
+ * @returns {Promise<CustomerBE>} Created or updated customer
81
+ */
82
+ export declare const updateCustomer: ({ prisma, id, queryWhere, address, city, country, email, firstName, lastName, phone, include, }: UpdateCustomerArgs) => Promise<CustomerBE>;
83
+ /**
84
+ * Deletes a customer by ID
85
+ * @param {DeleteCustomerArgs} args - Object containing prisma client and query where conditions
86
+ * @returns {Promise<CustomerBE>} Deleted customer
87
+ * @throws {Error} If customer ID is not provided or customer not found
88
+ */
89
+ export declare const deleteCustomer: ({ prisma, queryWhere, include, }: DeleteCustomerArgs) => Promise<CustomerBE>;
48
90
  export {};
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/array-type */
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,135 +47,155 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
47
  }
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.deleteCustomer = exports.postCustomer = exports.postCustomers = exports.getCustomerByPhone = exports.getCustomerById = exports.getCustomers = void 0;
41
- var getCustomers = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var customers;
43
- var prisma = _b.prisma;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0: return [4 /*yield*/, prisma.customer.findMany({
47
- orderBy: {
48
- createdAt: 'desc',
49
- },
50
- include: {
51
- invoices: true,
52
- },
53
- })];
50
+ exports.deleteCustomer = exports.updateCustomer = exports.unitCustomerByPhone = exports.unitCustomerById = exports.listCustomer = void 0;
51
+ /**
52
+ * Retrieves customers with pagination and filtering
53
+ * @param {ListCustomerArgs} args - Object containing prisma client, pagination, and query options
54
+ * @returns {Promise<[number, Array<CustomerBE>]>} Tuple containing total count and array of customers
55
+ */
56
+ var listCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
+ var _c, count, customers;
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('Valid current page is required');
64
+ }
65
+ if (pageLimit < 1) {
66
+ throw new Error('Valid page limit is required');
67
+ }
68
+ return [4 /*yield*/, prisma.$transaction([
69
+ prisma.customer.count({
70
+ where: queryWhere,
71
+ }),
72
+ prisma.customer.findMany({
73
+ orderBy: orderBy,
74
+ include: include,
75
+ where: queryWhere,
76
+ take: pageLimit,
77
+ skip: (currentPage - 1) * pageLimit,
78
+ }),
79
+ ])];
54
80
  case 1:
55
- customers = _c.sent();
56
- return [2 /*return*/, customers];
81
+ _c = _g.sent(), count = _c[0], customers = _c[1];
82
+ return [2 /*return*/, [count, customers]];
57
83
  }
58
84
  });
59
85
  }); };
60
- exports.getCustomers = getCustomers;
61
- var getCustomerById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
86
+ exports.listCustomer = listCustomer;
87
+ /**
88
+ * Retrieves a single customer by ID
89
+ * @param {UnitCustomerByIdArgs} args - Object containing prisma client and query where conditions
90
+ * @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
91
+ */
92
+ var unitCustomerById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
62
93
  var customer;
63
- var prisma = _b.prisma, id = _b.id;
64
- return __generator(this, function (_c) {
65
- switch (_c.label) {
66
- case 0: return [4 /*yield*/, prisma.customer.findUnique({
67
- where: {
68
- id: id,
69
- },
70
- include: {
71
- invoices: true,
72
- },
73
- })];
94
+ var prisma = _b.prisma, queryWhere = _b.queryWhere, _c = _b.include, include = _c === void 0 ? {} : _c;
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('Customer ID is required');
100
+ }
101
+ return [4 /*yield*/, prisma.customer.findUnique({
102
+ include: include,
103
+ where: queryWhere,
104
+ })];
74
105
  case 1:
75
- customer = _c.sent();
106
+ customer = _d.sent();
76
107
  return [2 /*return*/, customer];
77
108
  }
78
109
  });
79
110
  }); };
80
- exports.getCustomerById = getCustomerById;
81
- var getCustomerByPhone = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
111
+ exports.unitCustomerById = unitCustomerById;
112
+ /**
113
+ * Retrieves a single customer by phone number
114
+ * @param {UnitCustomerByPhoneArgs} args - Object containing prisma client and phone number
115
+ * @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
116
+ */
117
+ var unitCustomerByPhone = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
82
118
  var customer;
83
- var prisma = _b.prisma, phone = _b.phone;
84
- return __generator(this, function (_c) {
85
- switch (_c.label) {
86
- case 0: return [4 /*yield*/, prisma.customer.findUnique({
87
- where: {
88
- phone: phone,
89
- },
90
- })];
119
+ var prisma = _b.prisma, phone = _b.phone, _c = _b.include, include = _c === void 0 ? {} : _c;
120
+ return __generator(this, function (_d) {
121
+ switch (_d.label) {
122
+ case 0:
123
+ if (!phone) {
124
+ throw new Error('Phone number is required');
125
+ }
126
+ return [4 /*yield*/, prisma.customer.findUnique({
127
+ include: include,
128
+ where: {
129
+ phone: phone,
130
+ },
131
+ })];
91
132
  case 1:
92
- customer = _c.sent();
133
+ customer = _d.sent();
93
134
  return [2 /*return*/, customer];
94
135
  }
95
136
  });
96
137
  }); };
97
- exports.getCustomerByPhone = getCustomerByPhone;
98
- var postCustomers = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
99
- var customers;
100
- var currentPage = _b.currentPage, include = _b.include, orderBy = _b.orderBy, pageLimit = _b.pageLimit, prisma = _b.prisma, queryWhere = _b.queryWhere;
138
+ exports.unitCustomerByPhone = unitCustomerByPhone;
139
+ /**
140
+ * Creates or updates a customer
141
+ * @param {UpdateCustomerArgs} args - Object containing prisma client and customer data
142
+ * @returns {Promise<CustomerBE>} Created or updated customer
143
+ */
144
+ var updateCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
145
+ var customerData, customer;
146
+ var prisma = _b.prisma, id = _b.id, queryWhere = _b.queryWhere, address = _b.address, city = _b.city, country = _b.country, email = _b.email, firstName = _b.firstName, lastName = _b.lastName, phone = _b.phone, include = _b.include;
101
147
  return __generator(this, function (_c) {
102
148
  switch (_c.label) {
103
- case 0: return [4 /*yield*/, prisma.$transaction([
104
- prisma.customer.count({
149
+ case 0:
150
+ if (!id || !(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
151
+ throw new Error('Customer ID is required');
152
+ }
153
+ if (!city || !country || !firstName || !lastName || !phone) {
154
+ throw new Error('City, country, first name, last name, and phone are required');
155
+ }
156
+ customerData = {
157
+ address: address || null,
158
+ city: city,
159
+ country: country,
160
+ email: email || null,
161
+ firstName: firstName,
162
+ lastName: lastName,
163
+ phone: phone,
164
+ };
165
+ return [4 /*yield*/, prisma.customer.upsert({
105
166
  where: queryWhere,
106
- }),
107
- prisma.customer.findMany({
108
- orderBy: orderBy,
167
+ update: customerData,
168
+ create: __assign({ id: id }, customerData),
109
169
  include: include,
110
- where: queryWhere,
111
- take: pageLimit,
112
- skip: (currentPage - 1) * pageLimit,
113
- }),
114
- ])];
115
- case 1:
116
- customers = _c.sent();
117
- return [2 /*return*/, customers];
118
- }
119
- });
120
- }); };
121
- exports.postCustomers = postCustomers;
122
- var postCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
123
- var customer;
124
- var prisma = _b.prisma, id = _b.id, address = _b.address, city = _b.city, country = _b.country, email = _b.email, firstName = _b.firstName, lastName = _b.lastName, phone = _b.phone;
125
- return __generator(this, function (_c) {
126
- switch (_c.label) {
127
- case 0: return [4 /*yield*/, prisma.customer.upsert({
128
- where: {
129
- id: id,
130
- },
131
- update: {
132
- address: address,
133
- city: city,
134
- country: country,
135
- email: email,
136
- firstName: firstName,
137
- lastName: lastName,
138
- phone: phone,
139
- },
140
- create: {
141
- address: address,
142
- city: city,
143
- country: country,
144
- email: email,
145
- firstName: firstName,
146
- lastName: lastName,
147
- phone: phone,
148
- },
149
- })];
170
+ })];
150
171
  case 1:
151
172
  customer = _c.sent();
152
173
  return [2 /*return*/, customer];
153
174
  }
154
175
  });
155
176
  }); };
156
- exports.postCustomer = postCustomer;
177
+ exports.updateCustomer = updateCustomer;
178
+ /**
179
+ * Deletes a customer by ID
180
+ * @param {DeleteCustomerArgs} args - Object containing prisma client and query where conditions
181
+ * @returns {Promise<CustomerBE>} Deleted customer
182
+ * @throws {Error} If customer ID is not provided or customer not found
183
+ */
157
184
  var deleteCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
158
185
  var customer;
159
- var prisma = _b.prisma, id = _b.id;
160
- return __generator(this, function (_c) {
161
- switch (_c.label) {
162
- case 0: return [4 /*yield*/, prisma.customer.delete({
163
- where: {
164
- id: id,
165
- },
166
- })];
186
+ var prisma = _b.prisma, queryWhere = _b.queryWhere, _c = _b.include, include = _c === void 0 ? {} : _c;
187
+ return __generator(this, function (_d) {
188
+ switch (_d.label) {
189
+ case 0:
190
+ if (!(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
191
+ throw new Error('Customer ID is required');
192
+ }
193
+ return [4 /*yield*/, prisma.customer.delete({
194
+ include: include,
195
+ where: queryWhere,
196
+ })];
167
197
  case 1:
168
- customer = _c.sent();
198
+ customer = _d.sent();
169
199
  return [2 /*return*/, customer];
170
200
  }
171
201
  });