@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.
- package/README.md +6 -3
- package/api/stellar-solutions/app-user/index.d.ts +63 -14
- package/api/stellar-solutions/app-user/index.js +106 -52
- package/api/stellar-solutions/bank/index.d.ts +65 -16
- package/api/stellar-solutions/bank/index.js +115 -65
- package/api/stellar-solutions/branch/index.d.ts +64 -15
- package/api/stellar-solutions/branch/index.js +119 -65
- package/api/stellar-solutions/company/index.d.ts +58 -24
- package/api/stellar-solutions/company/index.js +106 -78
- package/api/stellar-solutions/company-report/index.d.ts +12 -5
- package/api/stellar-solutions/company-report/index.js +12 -7
- package/api/stellar-solutions/contact/index.d.ts +54 -20
- package/api/stellar-solutions/contact/index.js +109 -88
- package/api/stellar-solutions/currency/index.d.ts +63 -14
- package/api/stellar-solutions/currency/index.js +113 -61
- package/api/stellar-solutions/customer/index.d.ts +70 -28
- package/api/stellar-solutions/customer/index.js +131 -101
- package/api/stellar-solutions/expense/index.d.ts +58 -22
- package/api/stellar-solutions/expense/index.js +128 -92
- package/api/stellar-solutions/expense-category/index.d.ts +58 -22
- package/api/stellar-solutions/expense-category/index.js +125 -86
- package/api/stellar-solutions/lead/index.js +0 -1
- package/api/stellar-solutions/menu-order/index.d.ts +29 -7
- package/api/stellar-solutions/menu-order/index.js +74 -27
- package/api/stellar-solutions/payment/index.d.ts +62 -27
- package/api/stellar-solutions/payment/index.js +144 -123
- package/api/stellar-solutions/payment-mode/index.d.ts +44 -12
- package/api/stellar-solutions/payment-mode/index.js +115 -49
- package/api/stellar-solutions/preference/index.d.ts +14 -3
- package/api/stellar-solutions/preference/index.js +44 -14
- package/api/stellar-solutions/product/index.d.ts +46 -31
- package/api/stellar-solutions/product/index.js +142 -113
- package/api/stellar-solutions/product-category/index.d.ts +44 -27
- package/api/stellar-solutions/product-category/index.js +123 -87
- package/api/stellar-solutions/profile/index.d.ts +48 -17
- package/api/stellar-solutions/profile/index.js +124 -65
- package/api/stellar-solutions/quote-invoice/index.d.ts +67 -8
- package/api/stellar-solutions/quote-invoice/index.js +123 -57
- package/api/stellar-solutions/quote-invoice-report/index.d.ts +12 -5
- package/api/stellar-solutions/quote-invoice-report/index.js +10 -5
- package/api/stellar-solutions/tax/index.d.ts +46 -14
- package/api/stellar-solutions/tax/index.js +135 -63
- package/api/stellar-solutions/type.d.ts +292 -177
- package/api/stellar-solutions/type.js +93 -1
- package/constants/countries-timezones.js +0 -1
- package/constants/currencies.js +0 -1
- package/general/basic-get.js +22 -21
- package/general/basic-post.js +19 -18
- package/general/calculate-pages.js +3 -1
- package/general/check-even-odd-length.js +3 -2
- package/general/delete-image-from-private-supabase.js +0 -1
- package/general/delete-image-from-public-supabase.js +0 -1
- package/general/dynamic-page-limit.js +3 -2
- package/general/enum-to-text.js +7 -4
- package/general/fetch-data.js +0 -1
- package/general/fetch-supabase-image.js +0 -1
- package/general/fetch-supabase-private-assets.js +15 -14
- package/general/format-date.js +8 -8
- package/general/format-number.js +3 -2
- package/general/format-time.js +3 -2
- package/general/full-year-range.js +2 -2
- package/general/generate-blog-schema.d.ts +3 -3
- package/general/generate-blog-schema.js +20 -13
- package/general/generate-breadcrumb-schema.d.ts +4 -4
- package/general/generate-breadcrumb-schema.js +9 -10
- package/general/generate-faq-schema.d.ts +5 -5
- package/general/generate-faq-schema.js +18 -11
- package/general/generate-grid.js +0 -1
- package/general/generate-organization-schema.d.ts +3 -3
- package/general/generate-organization-schema.js +25 -18
- package/general/get-available-page-limit.js +2 -2
- package/general/get-calendar-dates.js +14 -3
- package/general/get-full-name.d.ts +1 -1
- package/general/get-number-of-days-in-month.d.ts +1 -1
- package/general/get-pathname.js +4 -1
- package/general/is-odd.js +1 -1
- package/general/is-previous-button-disabled.js +3 -1
- package/general/parse-frontmatter.js +0 -1
- package/general/remove-data-image-prefix.js +3 -2
- package/general/repeat-times.js +0 -1
- package/general/resolve-current-date.js +1 -2
- package/general/resolve-grid.js +3 -2
- package/general/slugify.js +11 -9
- package/general/text-to-enum.js +6 -1
- package/general/text-to-sentence-case.js +3 -1
- package/general/time-out.js +5 -4
- package/general/truncate-text.js +3 -1
- package/general/upload-blob-to-private-supabase.js +2 -2
- package/general/upload-blob-to-public-supabase.js +2 -2
- package/general/upload-image-to-private-supabase.js +2 -2
- package/general/upload-image-to-public-supabase.js +2 -2
- package/general/validate-email.js +1 -1
- package/hooks/use-fetch.js +11 -12
- package/hooks/use-module-entity.js +5 -6
- package/hooks/use-sticky.js +0 -1
- package/hooks/with-seo.d.ts +1 -1
- package/hooks/with-seo.js +3 -4
- package/local-storage/get-storage-value.js +0 -1
- package/package.json +22 -13
- package/setupTests.js +1 -2
- package/storybook/generate-sitemap.js +0 -1
- package/storybook/preview.js +1 -4
- package/storybook/react-design-story-script.js +0 -2
- package/storybook/react-emoji-collection.js +8 -6
- package/storybook/react-emoji-story-script.js +0 -2
- package/storybook/react-icon-collection.js +4 -3
- package/storybook/react-icon-story-script.js +0 -2
- package/storybook/react-logo-collection.js +4 -3
- package/storybook/react-logo-story-script.js +0 -2
- package/storybook/responsive-component.js +14 -7
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
53
|
-
return [2 /*return*/,
|
|
81
|
+
_c = _g.sent(), count = _c[0], currencies = _c[1];
|
|
82
|
+
return [2 /*return*/, [count, currencies]];
|
|
54
83
|
}
|
|
55
84
|
});
|
|
56
85
|
}); };
|
|
57
|
-
exports.
|
|
58
|
-
|
|
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
|
|
61
|
-
return __generator(this, function (
|
|
62
|
-
switch (
|
|
63
|
-
case 0:
|
|
64
|
-
|
|
65
|
-
|
|
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 =
|
|
106
|
+
currency = _d.sent();
|
|
70
107
|
return [2 /*return*/, currency];
|
|
71
108
|
}
|
|
72
109
|
});
|
|
73
110
|
}); };
|
|
74
|
-
exports.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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 =
|
|
143
|
+
currency = _d.sent();
|
|
101
144
|
return [2 /*return*/, currency];
|
|
102
145
|
}
|
|
103
146
|
});
|
|
104
147
|
}); };
|
|
105
|
-
exports.
|
|
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
|
|
109
|
-
return __generator(this, function (
|
|
110
|
-
switch (
|
|
111
|
-
case 0:
|
|
112
|
-
|
|
113
|
-
|
|
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 =
|
|
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
|
-
|
|
3
|
-
|
|
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:
|
|
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
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
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
|
-
|
|
40
|
-
|
|
51
|
+
include?: {
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
};
|
|
54
|
+
prisma: PrismaClient;
|
|
55
|
+
queryWhere: {
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
};
|
|
41
58
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export declare const
|
|
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
|
-
|
|
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.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
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.
|
|
61
|
-
|
|
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,
|
|
64
|
-
return __generator(this, function (
|
|
65
|
-
switch (
|
|
66
|
-
case 0:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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 =
|
|
106
|
+
customer = _d.sent();
|
|
76
107
|
return [2 /*return*/, customer];
|
|
77
108
|
}
|
|
78
109
|
});
|
|
79
110
|
}); };
|
|
80
|
-
exports.
|
|
81
|
-
|
|
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 (
|
|
85
|
-
switch (
|
|
86
|
-
case 0:
|
|
87
|
-
|
|
88
|
-
|
|
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 =
|
|
133
|
+
customer = _d.sent();
|
|
93
134
|
return [2 /*return*/, customer];
|
|
94
135
|
}
|
|
95
136
|
});
|
|
96
137
|
}); };
|
|
97
|
-
exports.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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:
|
|
104
|
-
|
|
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
|
-
|
|
108
|
-
orderBy: orderBy,
|
|
167
|
+
update: customerData,
|
|
168
|
+
create: __assign({ id: id }, customerData),
|
|
109
169
|
include: include,
|
|
110
|
-
|
|
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.
|
|
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,
|
|
160
|
-
return __generator(this, function (
|
|
161
|
-
switch (
|
|
162
|
-
case 0:
|
|
163
|
-
|
|
164
|
-
|
|
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 =
|
|
198
|
+
customer = _d.sent();
|
|
169
199
|
return [2 /*return*/, customer];
|
|
170
200
|
}
|
|
171
201
|
});
|