@react-pakistan/util-functions 1.24.69 → 1.24.72
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/api/stellar-solutions/app-user/index.d.ts +8 -7
- package/api/stellar-solutions/app-user/index.js +60 -24
- package/api/stellar-solutions/bank/index.d.ts +11 -8
- package/api/stellar-solutions/bank/index.js +58 -20
- package/api/stellar-solutions/branch/index.d.ts +11 -8
- package/api/stellar-solutions/branch/index.js +61 -17
- package/api/stellar-solutions/company/index.d.ts +13 -8
- package/api/stellar-solutions/company/index.js +70 -28
- package/api/stellar-solutions/company-report/index.d.ts +1 -1
- package/api/stellar-solutions/contact/index.d.ts +12 -9
- package/api/stellar-solutions/contact/index.js +70 -22
- package/api/stellar-solutions/currency/index.d.ts +11 -8
- package/api/stellar-solutions/currency/index.js +66 -31
- package/api/stellar-solutions/customer/index.d.ts +14 -10
- package/api/stellar-solutions/customer/index.js +80 -35
- package/api/stellar-solutions/expense/index.d.ts +8 -7
- package/api/stellar-solutions/expense/index.js +77 -29
- package/api/stellar-solutions/expense-category/index.d.ts +8 -9
- package/api/stellar-solutions/expense-category/index.js +45 -30
- package/api/stellar-solutions/lead/index.d.ts +6 -5
- package/api/stellar-solutions/lead/index.js +46 -28
- package/api/stellar-solutions/menu-order/index.d.ts +11 -8
- package/api/stellar-solutions/menu-order/index.js +56 -29
- package/api/stellar-solutions/payment/index.d.ts +9 -8
- package/api/stellar-solutions/payment/index.js +56 -39
- package/api/stellar-solutions/payment-mode/index.d.ts +13 -7
- package/api/stellar-solutions/payment-mode/index.js +65 -33
- package/api/stellar-solutions/preference/index.d.ts +4 -4
- package/api/stellar-solutions/preference/index.js +11 -11
- package/api/stellar-solutions/product/index.d.ts +9 -12
- package/api/stellar-solutions/product/index.js +45 -32
- package/api/stellar-solutions/product-category/index.d.ts +8 -9
- package/api/stellar-solutions/product-category/index.js +45 -30
- package/api/stellar-solutions/quote-invoice/index.d.ts +9 -8
- package/api/stellar-solutions/quote-invoice/index.js +40 -25
- package/api/stellar-solutions/quote-invoice-report/index.d.ts +1 -1
- package/api/stellar-solutions/tax/index.d.ts +9 -6
- package/api/stellar-solutions/tax/index.js +44 -21
- package/package.json +1 -1
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { CustomerBE } from '../type';
|
|
2
2
|
type PrismaClient = any;
|
|
3
|
-
interface ListCustomerArgs {
|
|
4
|
-
currentPage
|
|
3
|
+
export interface ListCustomerArgs {
|
|
4
|
+
currentPage?: number;
|
|
5
|
+
includeQuotesInvoices?: boolean;
|
|
5
6
|
orderByColumn?: string;
|
|
6
7
|
orderByDirection?: 'asc' | 'desc';
|
|
7
|
-
pageLimit
|
|
8
|
+
pageLimit?: number;
|
|
8
9
|
prisma: PrismaClient;
|
|
10
|
+
searchQuery?: string;
|
|
9
11
|
}
|
|
10
|
-
interface UnitCustomerByIdArgs {
|
|
12
|
+
export interface UnitCustomerByIdArgs {
|
|
11
13
|
id: string;
|
|
14
|
+
includeQuotesInvoices?: boolean;
|
|
12
15
|
prisma: PrismaClient;
|
|
13
16
|
}
|
|
14
|
-
interface UnitCustomerByPhoneArgs {
|
|
17
|
+
export interface UnitCustomerByPhoneArgs {
|
|
18
|
+
includeQuotesInvoices?: boolean;
|
|
15
19
|
phone: string;
|
|
16
20
|
prisma: PrismaClient;
|
|
17
21
|
}
|
|
18
|
-
interface UpdateCustomerArgs {
|
|
22
|
+
export interface UpdateCustomerArgs {
|
|
19
23
|
address?: string;
|
|
20
24
|
city: string;
|
|
21
25
|
country: string;
|
|
@@ -26,7 +30,7 @@ interface UpdateCustomerArgs {
|
|
|
26
30
|
phone: string;
|
|
27
31
|
prisma: PrismaClient;
|
|
28
32
|
}
|
|
29
|
-
interface DeleteCustomerArgs {
|
|
33
|
+
export interface DeleteCustomerArgs {
|
|
30
34
|
id: string;
|
|
31
35
|
prisma: PrismaClient;
|
|
32
36
|
}
|
|
@@ -35,19 +39,19 @@ interface DeleteCustomerArgs {
|
|
|
35
39
|
* @param {ListCustomerArgs} args - Object containing prisma client, pagination, and query options
|
|
36
40
|
* @returns {Promise<[number, Array<CustomerBE>]>} Tuple containing total count and array of customers
|
|
37
41
|
*/
|
|
38
|
-
export declare const listCustomer: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, }: ListCustomerArgs) => Promise<[number, Array<CustomerBE>]>;
|
|
42
|
+
export declare const listCustomer: ({ currentPage, includeQuotesInvoices, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListCustomerArgs) => Promise<[number, Array<CustomerBE>]>;
|
|
39
43
|
/**
|
|
40
44
|
* Retrieves a single customer by ID
|
|
41
45
|
* @param {UnitCustomerByIdArgs} args - Object containing prisma client and query where conditions
|
|
42
46
|
* @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
|
|
43
47
|
*/
|
|
44
|
-
export declare const unitCustomerById: ({ id, prisma, }: UnitCustomerByIdArgs) => Promise<CustomerBE | null>;
|
|
48
|
+
export declare const unitCustomerById: ({ id, prisma, includeQuotesInvoices, }: UnitCustomerByIdArgs) => Promise<CustomerBE | null>;
|
|
45
49
|
/**
|
|
46
50
|
* Retrieves a single customer by phone number
|
|
47
51
|
* @param {UnitCustomerByPhoneArgs} args - Object containing prisma client and phone number
|
|
48
52
|
* @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
|
|
49
53
|
*/
|
|
50
|
-
export declare const unitCustomerByPhone: ({ phone, prisma, }: UnitCustomerByPhoneArgs) => Promise<CustomerBE | null>;
|
|
54
|
+
export declare const unitCustomerByPhone: ({ includeQuotesInvoices, phone, prisma, }: UnitCustomerByPhoneArgs) => Promise<CustomerBE | null>;
|
|
51
55
|
/**
|
|
52
56
|
* Creates or updates a customer
|
|
53
57
|
* @param {UpdateCustomerArgs} args - Object containing prisma client and customer data
|
|
@@ -46,39 +46,80 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
49
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
59
|
exports.deleteCustomer = exports.updateCustomer = exports.unitCustomerByPhone = exports.unitCustomerById = exports.listCustomer = void 0;
|
|
60
|
+
var multi_part_search_1 = require("../../../general/multi-part-search");
|
|
51
61
|
/**
|
|
52
62
|
* Retrieves customers with pagination and filtering
|
|
53
63
|
* @param {ListCustomerArgs} args - Object containing prisma client, pagination, and query options
|
|
54
64
|
* @returns {Promise<[number, Array<CustomerBE>]>} Tuple containing total count and array of customers
|
|
55
65
|
*/
|
|
56
66
|
var listCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
57
|
-
var _c, count,
|
|
67
|
+
var include, orderBy, idSearchQuery, firstNameSearchQuery, lastNameSearchQuery, emailSearchQuery, phoneSearchQuery, where, _c, count, items;
|
|
58
68
|
var _d;
|
|
59
|
-
var
|
|
60
|
-
return __generator(this, function (
|
|
61
|
-
switch (
|
|
69
|
+
var _e = _b.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _b.includeQuotesInvoices, includeQuotesInvoices = _f === void 0 ? false : _f, _g = _b.orderByColumn, orderByColumn = _g === void 0 ? 'createdAt' : _g, _h = _b.orderByDirection, orderByDirection = _h === void 0 ? 'desc' : _h, _j = _b.pageLimit, pageLimit = _j === void 0 ? 5 : _j, prisma = _b.prisma, _k = _b.searchQuery, searchQuery = _k === void 0 ? '' : _k;
|
|
70
|
+
return __generator(this, function (_l) {
|
|
71
|
+
switch (_l.label) {
|
|
62
72
|
case 0:
|
|
63
|
-
if (currentPage < 1) {
|
|
73
|
+
if (!currentPage || currentPage < 1) {
|
|
64
74
|
throw new Error('Valid current page is required');
|
|
65
75
|
}
|
|
66
|
-
if (pageLimit < 1) {
|
|
76
|
+
if (!pageLimit || pageLimit < 1) {
|
|
67
77
|
throw new Error('Valid page limit is required');
|
|
68
78
|
}
|
|
79
|
+
include = {
|
|
80
|
+
quotesInvoices: includeQuotesInvoices,
|
|
81
|
+
};
|
|
82
|
+
orderBy = (_d = {},
|
|
83
|
+
_d[orderByColumn] = orderByDirection,
|
|
84
|
+
_d);
|
|
85
|
+
idSearchQuery = (0, multi_part_search_1.multiPartSearch)({
|
|
86
|
+
columnName: 'id',
|
|
87
|
+
fullText: searchQuery,
|
|
88
|
+
});
|
|
89
|
+
firstNameSearchQuery = (0, multi_part_search_1.multiPartSearch)({
|
|
90
|
+
columnName: 'firstName',
|
|
91
|
+
fullText: searchQuery,
|
|
92
|
+
});
|
|
93
|
+
lastNameSearchQuery = (0, multi_part_search_1.multiPartSearch)({
|
|
94
|
+
columnName: 'lastName',
|
|
95
|
+
fullText: searchQuery,
|
|
96
|
+
});
|
|
97
|
+
emailSearchQuery = (0, multi_part_search_1.multiPartSearch)({
|
|
98
|
+
columnName: 'email',
|
|
99
|
+
fullText: searchQuery,
|
|
100
|
+
});
|
|
101
|
+
phoneSearchQuery = (0, multi_part_search_1.multiPartSearch)({
|
|
102
|
+
columnName: 'phone',
|
|
103
|
+
fullText: searchQuery,
|
|
104
|
+
});
|
|
105
|
+
where = {
|
|
106
|
+
OR: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], idSearchQuery, true), firstNameSearchQuery, true), lastNameSearchQuery, true), emailSearchQuery, true), phoneSearchQuery, true),
|
|
107
|
+
};
|
|
69
108
|
return [4 /*yield*/, prisma.$transaction([
|
|
70
|
-
prisma.customer.count(
|
|
109
|
+
prisma.customer.count({
|
|
110
|
+
where: where,
|
|
111
|
+
}),
|
|
71
112
|
prisma.customer.findMany({
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
_d),
|
|
75
|
-
take: pageLimit,
|
|
113
|
+
include: include,
|
|
114
|
+
orderBy: orderBy,
|
|
76
115
|
skip: (currentPage - 1) * pageLimit,
|
|
116
|
+
take: pageLimit,
|
|
117
|
+
where: where,
|
|
77
118
|
}),
|
|
78
119
|
])];
|
|
79
120
|
case 1:
|
|
80
|
-
_c =
|
|
81
|
-
return [2 /*return*/, [count,
|
|
121
|
+
_c = _l.sent(), count = _c[0], items = _c[1];
|
|
122
|
+
return [2 /*return*/, [count, items]];
|
|
82
123
|
}
|
|
83
124
|
});
|
|
84
125
|
}); };
|
|
@@ -89,18 +130,21 @@ exports.listCustomer = listCustomer;
|
|
|
89
130
|
* @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
|
|
90
131
|
*/
|
|
91
132
|
var unitCustomerById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
92
|
-
var customer;
|
|
93
|
-
var id = _b.id, prisma = _b.prisma;
|
|
133
|
+
var include, where, customer;
|
|
134
|
+
var id = _b.id, prisma = _b.prisma, includeQuotesInvoices = _b.includeQuotesInvoices;
|
|
94
135
|
return __generator(this, function (_c) {
|
|
95
136
|
switch (_c.label) {
|
|
96
137
|
case 0:
|
|
97
138
|
if (!id) {
|
|
98
139
|
throw new Error('Customer ID is required');
|
|
99
140
|
}
|
|
141
|
+
include = {
|
|
142
|
+
quotesInvoices: includeQuotesInvoices,
|
|
143
|
+
};
|
|
144
|
+
where = { id: id };
|
|
100
145
|
return [4 /*yield*/, prisma.customer.findUnique({
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
},
|
|
146
|
+
include: include,
|
|
147
|
+
where: where,
|
|
104
148
|
})];
|
|
105
149
|
case 1:
|
|
106
150
|
customer = _c.sent();
|
|
@@ -115,21 +159,24 @@ exports.unitCustomerById = unitCustomerById;
|
|
|
115
159
|
* @returns {Promise<CustomerBE | null>} Customer if found, null otherwise
|
|
116
160
|
*/
|
|
117
161
|
var unitCustomerByPhone = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
118
|
-
var customer;
|
|
119
|
-
var phone = _b.phone, prisma = _b.prisma;
|
|
120
|
-
return __generator(this, function (
|
|
121
|
-
switch (
|
|
162
|
+
var include, where, customer;
|
|
163
|
+
var _c = _b.includeQuotesInvoices, includeQuotesInvoices = _c === void 0 ? false : _c, phone = _b.phone, prisma = _b.prisma;
|
|
164
|
+
return __generator(this, function (_d) {
|
|
165
|
+
switch (_d.label) {
|
|
122
166
|
case 0:
|
|
123
167
|
if (!phone) {
|
|
124
168
|
throw new Error('Phone number is required');
|
|
125
169
|
}
|
|
170
|
+
include = {
|
|
171
|
+
quotesInvoices: includeQuotesInvoices,
|
|
172
|
+
};
|
|
173
|
+
where = { phone: phone };
|
|
126
174
|
return [4 /*yield*/, prisma.customer.findUnique({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
},
|
|
175
|
+
include: include,
|
|
176
|
+
where: where,
|
|
130
177
|
})];
|
|
131
178
|
case 1:
|
|
132
|
-
customer =
|
|
179
|
+
customer = _d.sent();
|
|
133
180
|
return [2 /*return*/, customer];
|
|
134
181
|
}
|
|
135
182
|
});
|
|
@@ -141,7 +188,7 @@ exports.unitCustomerByPhone = unitCustomerByPhone;
|
|
|
141
188
|
* @returns {Promise<CustomerBE>} Created or updated customer
|
|
142
189
|
*/
|
|
143
190
|
var updateCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
144
|
-
var customerData, customer;
|
|
191
|
+
var customerData, where, customer;
|
|
145
192
|
var address = _b.address, city = _b.city, country = _b.country, email = _b.email, firstName = _b.firstName, id = _b.id, lastName = _b.lastName, phone = _b.phone, prisma = _b.prisma;
|
|
146
193
|
return __generator(this, function (_c) {
|
|
147
194
|
switch (_c.label) {
|
|
@@ -161,12 +208,11 @@ var updateCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, func
|
|
|
161
208
|
lastName: lastName,
|
|
162
209
|
phone: phone,
|
|
163
210
|
};
|
|
211
|
+
where = { id: id };
|
|
164
212
|
return [4 /*yield*/, prisma.customer.upsert({
|
|
165
|
-
where: {
|
|
166
|
-
id: id,
|
|
167
|
-
},
|
|
168
|
-
update: customerData,
|
|
169
213
|
create: __assign({ id: id }, customerData),
|
|
214
|
+
update: customerData,
|
|
215
|
+
where: where,
|
|
170
216
|
})];
|
|
171
217
|
case 1:
|
|
172
218
|
customer = _c.sent();
|
|
@@ -182,7 +228,7 @@ exports.updateCustomer = updateCustomer;
|
|
|
182
228
|
* @throws {Error} If customer ID is not provided or customer not found
|
|
183
229
|
*/
|
|
184
230
|
var deleteCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
185
|
-
var customer;
|
|
231
|
+
var where, customer;
|
|
186
232
|
var id = _b.id, prisma = _b.prisma;
|
|
187
233
|
return __generator(this, function (_c) {
|
|
188
234
|
switch (_c.label) {
|
|
@@ -190,10 +236,9 @@ var deleteCustomer = function (_a) { return __awaiter(void 0, [_a], void 0, func
|
|
|
190
236
|
if (!id) {
|
|
191
237
|
throw new Error('Customer ID is required');
|
|
192
238
|
}
|
|
239
|
+
where = { id: id };
|
|
193
240
|
return [4 /*yield*/, prisma.customer.delete({
|
|
194
|
-
where:
|
|
195
|
-
id: id,
|
|
196
|
-
},
|
|
241
|
+
where: where,
|
|
197
242
|
})];
|
|
198
243
|
case 1:
|
|
199
244
|
customer = _c.sent();
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { ExpenseBE } from '../type';
|
|
2
2
|
type PrismaClient = any;
|
|
3
|
-
interface ListExpenseArgs {
|
|
4
|
-
currentPage
|
|
3
|
+
export interface ListExpenseArgs {
|
|
4
|
+
currentPage?: number;
|
|
5
5
|
includeExpenseCategory?: boolean;
|
|
6
6
|
orderByColumn?: string;
|
|
7
7
|
orderByDirection?: 'asc' | 'desc';
|
|
8
|
-
pageLimit
|
|
8
|
+
pageLimit?: number;
|
|
9
9
|
prisma: PrismaClient;
|
|
10
|
+
searchQuery?: string;
|
|
10
11
|
}
|
|
11
|
-
interface UnitExpenseByIdArgs {
|
|
12
|
+
export interface UnitExpenseByIdArgs {
|
|
12
13
|
id: string;
|
|
13
14
|
includeExpenseCategory?: boolean;
|
|
14
15
|
prisma: PrismaClient;
|
|
15
16
|
}
|
|
16
|
-
interface UpdateExpenseArgs {
|
|
17
|
+
export interface UpdateExpenseArgs {
|
|
17
18
|
currency: string;
|
|
18
19
|
description: string;
|
|
19
20
|
expenseCategoryId: string;
|
|
@@ -24,7 +25,7 @@ interface UpdateExpenseArgs {
|
|
|
24
25
|
ref?: string;
|
|
25
26
|
total: string;
|
|
26
27
|
}
|
|
27
|
-
interface DeleteExpenseArgs {
|
|
28
|
+
export interface DeleteExpenseArgs {
|
|
28
29
|
id: string;
|
|
29
30
|
includeExpenseCategory?: boolean;
|
|
30
31
|
prisma: PrismaClient;
|
|
@@ -34,7 +35,7 @@ interface DeleteExpenseArgs {
|
|
|
34
35
|
* @param {ListExpenseArgs} args - Object containing prisma client, pagination, and query options
|
|
35
36
|
* @returns {Promise<[number, Array<ExpenseBE>]>} Tuple containing total count and array of expenses
|
|
36
37
|
*/
|
|
37
|
-
export declare const listExpense: ({ currentPage, includeExpenseCategory, orderByColumn, orderByDirection, pageLimit, prisma, }: ListExpenseArgs) => Promise<[number, Array<ExpenseBE>]>;
|
|
38
|
+
export declare const listExpense: ({ currentPage, includeExpenseCategory, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListExpenseArgs) => Promise<[number, Array<ExpenseBE>]>;
|
|
38
39
|
/**
|
|
39
40
|
* Retrieves a single expense by ID
|
|
40
41
|
* @param {UnitExpenseByIdArgs} args - Object containing prisma client, expense id, and optional query parameters
|
|
@@ -46,40 +46,76 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
49
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
59
|
exports.deleteExpense = exports.updateExpense = exports.unitExpenseById = exports.listExpense = void 0;
|
|
60
|
+
var multi_part_search_1 = require("../../../general/multi-part-search");
|
|
51
61
|
/**
|
|
52
62
|
* Retrieves expenses with pagination and filtering
|
|
53
63
|
* @param {ListExpenseArgs} args - Object containing prisma client, pagination, and query options
|
|
54
64
|
* @returns {Promise<[number, Array<ExpenseBE>]>} Tuple containing total count and array of expenses
|
|
55
65
|
*/
|
|
56
66
|
var listExpense = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
57
|
-
var _c, count,
|
|
67
|
+
var include, orderBy, idSearchQuery, nameSearchQuery, descriptionSearchQuery, refSearchQuery, where, _c, count, items;
|
|
58
68
|
var _d;
|
|
59
|
-
var currentPage = _b.currentPage, _e = _b.includeExpenseCategory, includeExpenseCategory = _e === void 0 ? false : _e, _f = _b.orderByColumn, orderByColumn = _f === void 0 ? 'createdAt' : _f, _g = _b.orderByDirection, orderByDirection = _g === void 0 ? 'desc' : _g, pageLimit = _b.pageLimit, prisma = _b.prisma;
|
|
60
|
-
return __generator(this, function (
|
|
61
|
-
switch (
|
|
69
|
+
var currentPage = _b.currentPage, _e = _b.includeExpenseCategory, includeExpenseCategory = _e === void 0 ? false : _e, _f = _b.orderByColumn, orderByColumn = _f === void 0 ? 'createdAt' : _f, _g = _b.orderByDirection, orderByDirection = _g === void 0 ? 'desc' : _g, pageLimit = _b.pageLimit, prisma = _b.prisma, _h = _b.searchQuery, searchQuery = _h === void 0 ? '' : _h;
|
|
70
|
+
return __generator(this, function (_j) {
|
|
71
|
+
switch (_j.label) {
|
|
62
72
|
case 0:
|
|
63
|
-
if (currentPage < 1) {
|
|
73
|
+
if (!currentPage || currentPage < 1) {
|
|
64
74
|
throw new Error('Current page must be greater than or equal to 1');
|
|
65
75
|
}
|
|
66
|
-
if (pageLimit < 1) {
|
|
76
|
+
if (!pageLimit || pageLimit < 1) {
|
|
67
77
|
throw new Error('Page limit must be greater than or equal to 1');
|
|
68
78
|
}
|
|
79
|
+
include = {
|
|
80
|
+
expenseCategory: includeExpenseCategory,
|
|
81
|
+
};
|
|
82
|
+
orderBy = (_d = {},
|
|
83
|
+
_d[orderByColumn] = orderByDirection,
|
|
84
|
+
_d);
|
|
85
|
+
idSearchQuery = (0, multi_part_search_1.multiPartSearch)({
|
|
86
|
+
columnName: 'id',
|
|
87
|
+
fullText: searchQuery,
|
|
88
|
+
});
|
|
89
|
+
nameSearchQuery = (0, multi_part_search_1.multiPartSearch)({
|
|
90
|
+
columnName: 'name',
|
|
91
|
+
fullText: searchQuery,
|
|
92
|
+
});
|
|
93
|
+
descriptionSearchQuery = (0, multi_part_search_1.multiPartSearch)({
|
|
94
|
+
columnName: 'description',
|
|
95
|
+
fullText: searchQuery,
|
|
96
|
+
});
|
|
97
|
+
refSearchQuery = (0, multi_part_search_1.multiPartSearch)({
|
|
98
|
+
columnName: 'ref',
|
|
99
|
+
fullText: searchQuery,
|
|
100
|
+
});
|
|
101
|
+
where = {
|
|
102
|
+
OR: __spreadArray(__spreadArray(__spreadArray(__spreadArray([], idSearchQuery, true), nameSearchQuery, true), descriptionSearchQuery, true), refSearchQuery, true),
|
|
103
|
+
};
|
|
69
104
|
return [4 /*yield*/, prisma.$transaction([
|
|
70
|
-
prisma.expense.count(
|
|
105
|
+
prisma.expense.count({
|
|
106
|
+
where: where,
|
|
107
|
+
}),
|
|
71
108
|
prisma.expense.findMany({
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
_d),
|
|
75
|
-
include: includeExpenseCategory ? { expenseCategory: true } : undefined,
|
|
109
|
+
include: include,
|
|
110
|
+
orderBy: orderBy,
|
|
76
111
|
take: pageLimit,
|
|
77
112
|
skip: (currentPage - 1) * pageLimit,
|
|
113
|
+
where: where,
|
|
78
114
|
}),
|
|
79
115
|
])];
|
|
80
116
|
case 1:
|
|
81
|
-
_c =
|
|
82
|
-
return [2 /*return*/, [count,
|
|
117
|
+
_c = _j.sent(), count = _c[0], items = _c[1];
|
|
118
|
+
return [2 /*return*/, [count, items]];
|
|
83
119
|
}
|
|
84
120
|
});
|
|
85
121
|
}); };
|
|
@@ -90,7 +126,7 @@ exports.listExpense = listExpense;
|
|
|
90
126
|
* @returns {Promise<ExpenseBE | null>} Expense with optional relations if found, null otherwise
|
|
91
127
|
*/
|
|
92
128
|
var unitExpenseById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
93
|
-
var expense;
|
|
129
|
+
var include, where, expense;
|
|
94
130
|
var id = _b.id, _c = _b.includeExpenseCategory, includeExpenseCategory = _c === void 0 ? false : _c, prisma = _b.prisma;
|
|
95
131
|
return __generator(this, function (_d) {
|
|
96
132
|
switch (_d.label) {
|
|
@@ -98,11 +134,15 @@ var unitExpenseById = function (_a) { return __awaiter(void 0, [_a], void 0, fun
|
|
|
98
134
|
if (!id) {
|
|
99
135
|
throw new Error('Expense ID is required');
|
|
100
136
|
}
|
|
137
|
+
include = {
|
|
138
|
+
expenseCategory: includeExpenseCategory,
|
|
139
|
+
};
|
|
140
|
+
where = {
|
|
141
|
+
id: id,
|
|
142
|
+
};
|
|
101
143
|
return [4 /*yield*/, prisma.expense.findUnique({
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
include: includeExpenseCategory ? { expenseCategory: true } : undefined,
|
|
144
|
+
include: include,
|
|
145
|
+
where: where,
|
|
106
146
|
})];
|
|
107
147
|
case 1:
|
|
108
148
|
expense = _d.sent();
|
|
@@ -117,7 +157,7 @@ exports.unitExpenseById = unitExpenseById;
|
|
|
117
157
|
* @returns {Promise<ExpenseBE>} Created or updated expense
|
|
118
158
|
*/
|
|
119
159
|
var updateExpense = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
120
|
-
var expenseData, expense;
|
|
160
|
+
var expenseData, include, where, expense;
|
|
121
161
|
var currency = _b.currency, description = _b.description, expenseCategoryId = _b.expenseCategoryId, id = _b.id, _c = _b.includeExpenseCategory, includeExpenseCategory = _c === void 0 ? true : _c, name = _b.name, prisma = _b.prisma, ref = _b.ref, total = _b.total;
|
|
122
162
|
return __generator(this, function (_d) {
|
|
123
163
|
switch (_d.label) {
|
|
@@ -136,13 +176,17 @@ var updateExpense = function (_a) { return __awaiter(void 0, [_a], void 0, funct
|
|
|
136
176
|
ref: ref || null,
|
|
137
177
|
total: total,
|
|
138
178
|
};
|
|
179
|
+
include = {
|
|
180
|
+
expenseCategory: includeExpenseCategory,
|
|
181
|
+
};
|
|
182
|
+
where = {
|
|
183
|
+
id: id,
|
|
184
|
+
};
|
|
139
185
|
return [4 /*yield*/, prisma.expense.upsert({
|
|
140
|
-
|
|
141
|
-
id: id,
|
|
142
|
-
},
|
|
143
|
-
update: expenseData,
|
|
186
|
+
include: include,
|
|
144
187
|
create: __assign({ id: id }, expenseData),
|
|
145
|
-
|
|
188
|
+
update: expenseData,
|
|
189
|
+
where: where,
|
|
146
190
|
})];
|
|
147
191
|
case 1:
|
|
148
192
|
expense = _d.sent();
|
|
@@ -158,7 +202,7 @@ exports.updateExpense = updateExpense;
|
|
|
158
202
|
* @throws {Error} If expense ID is not provided or expense not found
|
|
159
203
|
*/
|
|
160
204
|
var deleteExpense = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
161
|
-
var expense;
|
|
205
|
+
var include, where, expense;
|
|
162
206
|
var id = _b.id, _c = _b.includeExpenseCategory, includeExpenseCategory = _c === void 0 ? true : _c, prisma = _b.prisma;
|
|
163
207
|
return __generator(this, function (_d) {
|
|
164
208
|
switch (_d.label) {
|
|
@@ -166,11 +210,15 @@ var deleteExpense = function (_a) { return __awaiter(void 0, [_a], void 0, funct
|
|
|
166
210
|
if (!id) {
|
|
167
211
|
throw new Error('Expense ID is required');
|
|
168
212
|
}
|
|
213
|
+
include = {
|
|
214
|
+
expenseCategory: includeExpenseCategory,
|
|
215
|
+
};
|
|
216
|
+
where = {
|
|
217
|
+
id: id,
|
|
218
|
+
};
|
|
169
219
|
return [4 /*yield*/, prisma.expense.delete({
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
},
|
|
173
|
-
include: includeExpenseCategory ? { expenseCategory: true } : undefined,
|
|
220
|
+
include: include,
|
|
221
|
+
where: where,
|
|
174
222
|
})];
|
|
175
223
|
case 1:
|
|
176
224
|
expense = _d.sent();
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import { ExpenseCategoryBE } from '../type';
|
|
2
2
|
type PrismaClient = any;
|
|
3
|
-
interface ListExpenseCategoryArgs {
|
|
3
|
+
export interface ListExpenseCategoryArgs {
|
|
4
4
|
currentPage?: number;
|
|
5
5
|
includeExpenses?: boolean;
|
|
6
6
|
orderByColumn?: string;
|
|
7
7
|
orderByDirection?: 'asc' | 'desc';
|
|
8
8
|
pageLimit?: number;
|
|
9
9
|
prisma: PrismaClient;
|
|
10
|
+
searchQuery?: string;
|
|
10
11
|
}
|
|
11
|
-
interface UnitExpenseCategoryByIdArgs {
|
|
12
|
+
export interface UnitExpenseCategoryByIdArgs {
|
|
12
13
|
id: string;
|
|
13
14
|
includeExpenses?: boolean;
|
|
14
15
|
prisma: PrismaClient;
|
|
15
16
|
}
|
|
16
|
-
interface UpdateExpenseCategoryArgs {
|
|
17
|
+
export interface UpdateExpenseCategoryArgs {
|
|
17
18
|
color: string;
|
|
18
19
|
description?: string;
|
|
19
20
|
id: string;
|
|
20
|
-
includeExpenses?: boolean;
|
|
21
21
|
name: string;
|
|
22
22
|
prisma: PrismaClient;
|
|
23
23
|
}
|
|
24
|
-
interface DeleteExpenseCategoryArgs {
|
|
24
|
+
export interface DeleteExpenseCategoryArgs {
|
|
25
25
|
id: string;
|
|
26
|
-
includeExpenses?: boolean;
|
|
27
26
|
prisma: PrismaClient;
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
@@ -31,7 +30,7 @@ interface DeleteExpenseCategoryArgs {
|
|
|
31
30
|
* @param {ListExpenseCategoryArgs} args - Object containing prisma client, pagination, and query options
|
|
32
31
|
* @returns {Promise<[number, Array<ExpenseCategoryBE>]>} Tuple containing total count and array of expense categories
|
|
33
32
|
*/
|
|
34
|
-
export declare const listExpenseCategory: ({ currentPage, includeExpenses, orderByColumn, orderByDirection, pageLimit, prisma, }: ListExpenseCategoryArgs) => Promise<[number, Array<ExpenseCategoryBE>]>;
|
|
33
|
+
export declare const listExpenseCategory: ({ currentPage, includeExpenses, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListExpenseCategoryArgs) => Promise<[number, Array<ExpenseCategoryBE>]>;
|
|
35
34
|
/**
|
|
36
35
|
* Retrieves a single expense category by ID
|
|
37
36
|
* @param {UnitExpenseCategoryByIdArgs} args - Object containing prisma client, expense category id, and optional query parameters
|
|
@@ -43,12 +42,12 @@ export declare const unitExpenseCategoryById: ({ id, includeExpenses, prisma, }:
|
|
|
43
42
|
* @param {UpdateExpenseCategoryArgs} args - Object containing prisma client and expense category data
|
|
44
43
|
* @returns {Promise<ExpenseCategoryBE>} Created or updated expense category
|
|
45
44
|
*/
|
|
46
|
-
export declare const updateExpenseCategory: ({ color, description, id,
|
|
45
|
+
export declare const updateExpenseCategory: ({ color, description, id, name, prisma, }: UpdateExpenseCategoryArgs) => Promise<ExpenseCategoryBE>;
|
|
47
46
|
/**
|
|
48
47
|
* Deletes an expense category by ID
|
|
49
48
|
* @param {DeleteExpenseCategoryArgs} args - Object containing prisma client, expense category id, and optional query parameters
|
|
50
49
|
* @returns {Promise<ExpenseCategoryBE>} Deleted expense category
|
|
51
50
|
* @throws {Error} If expense category ID is not provided or expense category not found
|
|
52
51
|
*/
|
|
53
|
-
export declare const deleteExpenseCategory: ({ id,
|
|
52
|
+
export declare const deleteExpenseCategory: ({ id, prisma, }: DeleteExpenseCategoryArgs) => Promise<ExpenseCategoryBE>;
|
|
54
53
|
export {};
|