@react-pakistan/util-functions 1.24.70 → 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.
Files changed (39) hide show
  1. package/api/stellar-solutions/app-user/index.d.ts +8 -7
  2. package/api/stellar-solutions/app-user/index.js +60 -24
  3. package/api/stellar-solutions/bank/index.d.ts +11 -8
  4. package/api/stellar-solutions/bank/index.js +58 -20
  5. package/api/stellar-solutions/branch/index.d.ts +11 -8
  6. package/api/stellar-solutions/branch/index.js +61 -17
  7. package/api/stellar-solutions/company/index.d.ts +12 -8
  8. package/api/stellar-solutions/company/index.js +41 -27
  9. package/api/stellar-solutions/company-report/index.d.ts +1 -1
  10. package/api/stellar-solutions/contact/index.d.ts +12 -9
  11. package/api/stellar-solutions/contact/index.js +70 -22
  12. package/api/stellar-solutions/currency/index.d.ts +11 -8
  13. package/api/stellar-solutions/currency/index.js +66 -31
  14. package/api/stellar-solutions/customer/index.d.ts +14 -10
  15. package/api/stellar-solutions/customer/index.js +80 -35
  16. package/api/stellar-solutions/expense/index.d.ts +8 -7
  17. package/api/stellar-solutions/expense/index.js +77 -29
  18. package/api/stellar-solutions/expense-category/index.d.ts +8 -9
  19. package/api/stellar-solutions/expense-category/index.js +45 -30
  20. package/api/stellar-solutions/lead/index.d.ts +6 -5
  21. package/api/stellar-solutions/lead/index.js +46 -28
  22. package/api/stellar-solutions/menu-order/index.d.ts +11 -8
  23. package/api/stellar-solutions/menu-order/index.js +56 -29
  24. package/api/stellar-solutions/payment/index.d.ts +9 -8
  25. package/api/stellar-solutions/payment/index.js +56 -39
  26. package/api/stellar-solutions/payment-mode/index.d.ts +13 -7
  27. package/api/stellar-solutions/payment-mode/index.js +65 -33
  28. package/api/stellar-solutions/preference/index.d.ts +4 -4
  29. package/api/stellar-solutions/preference/index.js +11 -11
  30. package/api/stellar-solutions/product/index.d.ts +9 -12
  31. package/api/stellar-solutions/product/index.js +45 -32
  32. package/api/stellar-solutions/product-category/index.d.ts +8 -9
  33. package/api/stellar-solutions/product-category/index.js +45 -30
  34. package/api/stellar-solutions/quote-invoice/index.d.ts +9 -8
  35. package/api/stellar-solutions/quote-invoice/index.js +40 -25
  36. package/api/stellar-solutions/quote-invoice-report/index.d.ts +1 -1
  37. package/api/stellar-solutions/tax/index.d.ts +9 -6
  38. package/api/stellar-solutions/tax/index.js +44 -21
  39. package/package.json +1 -1
@@ -1,17 +1,18 @@
1
1
  import { LeadBE } from '../type';
2
2
  type PrismaClient = any;
3
- interface ListLeadArgs {
3
+ export interface ListLeadArgs {
4
4
  currentPage?: number;
5
5
  orderByColumn?: string;
6
6
  orderByDirection?: 'asc' | 'desc';
7
7
  pageLimit?: number;
8
8
  prisma: PrismaClient;
9
+ searchQuery?: string;
9
10
  }
10
- interface UnitLeadByIdArgs {
11
+ export interface UnitLeadByIdArgs {
11
12
  id: string;
12
13
  prisma: PrismaClient;
13
14
  }
14
- interface UpdateLeadArgs {
15
+ export interface UpdateLeadArgs {
15
16
  id: string;
16
17
  notes: string;
17
18
  prisma: PrismaClient;
@@ -19,7 +20,7 @@ interface UpdateLeadArgs {
19
20
  status: string;
20
21
  type: string;
21
22
  }
22
- interface DeleteLeadArgs {
23
+ export interface DeleteLeadArgs {
23
24
  id: string;
24
25
  prisma: PrismaClient;
25
26
  }
@@ -28,7 +29,7 @@ interface DeleteLeadArgs {
28
29
  * @param {ListLeadArgs} args - Object containing prisma client, pagination, filtering, and ordering options
29
30
  * @returns {Promise<[number, Array<LeadBE>]>} Tuple containing total count and array of leads
30
31
  */
31
- export declare const listLead: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, }: ListLeadArgs) => Promise<[number, Array<LeadBE>]>;
32
+ export declare const listLead: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListLeadArgs) => Promise<[number, Array<LeadBE>]>;
32
33
  /**
33
34
  * Retrieves a single lead by its ID
34
35
  * @param {UnitLeadByIdArgs} args - Object containing prisma client and lead ID
@@ -46,32 +46,51 @@ 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.deleteLead = exports.updateLead = exports.unitLeadById = exports.listLead = void 0;
60
+ var multi_part_search_1 = require("../../../general/multi-part-search");
51
61
  /**
52
62
  * Retrieves a paginated list of leads
53
63
  * @param {ListLeadArgs} args - Object containing prisma client, pagination, filtering, and ordering options
54
64
  * @returns {Promise<[number, Array<LeadBE>]>} Tuple containing total count and array of leads
55
65
  */
56
66
  var listLead = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var include, orderBy, skip, where, _c, count, items;
67
+ var include, orderBy, idSearchQuery, notesSearchQuery, where, _c, count, items;
58
68
  var _d;
59
- var _e = _b.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _b.orderByColumn, orderByColumn = _f === void 0 ? 'createdAt' : _f, _g = _b.orderByDirection, orderByDirection = _g === void 0 ? 'desc' : _g, _h = _b.pageLimit, pageLimit = _h === void 0 ? 10 : _h, prisma = _b.prisma;
60
- return __generator(this, function (_j) {
61
- switch (_j.label) {
69
+ var _e = _b.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _b.orderByColumn, orderByColumn = _f === void 0 ? 'createdAt' : _f, _g = _b.orderByDirection, orderByDirection = _g === void 0 ? 'desc' : _g, _h = _b.pageLimit, pageLimit = _h === void 0 ? 5 : _h, prisma = _b.prisma, _j = _b.searchQuery, searchQuery = _j === void 0 ? '' : _j;
70
+ return __generator(this, function (_k) {
71
+ switch (_k.label) {
62
72
  case 0:
63
- if (currentPage < 1) {
64
- throw new Error('Current page must be greater than 0');
73
+ if (!currentPage || currentPage < 1) {
74
+ throw new Error('Valid current page is required');
65
75
  }
66
- if (pageLimit < 1) {
67
- throw new Error('Page limit must be greater than 0');
76
+ if (!pageLimit || pageLimit < 1) {
77
+ throw new Error('Valid page limit is required');
68
78
  }
69
79
  include = {};
70
80
  orderBy = (_d = {},
71
81
  _d[orderByColumn] = orderByDirection,
72
82
  _d);
73
- skip = (currentPage - 1) * pageLimit;
74
- where = {};
83
+ idSearchQuery = (0, multi_part_search_1.multiPartSearch)({
84
+ columnName: 'id',
85
+ fullText: searchQuery,
86
+ });
87
+ notesSearchQuery = (0, multi_part_search_1.multiPartSearch)({
88
+ columnName: 'notes',
89
+ fullText: searchQuery,
90
+ });
91
+ where = {
92
+ OR: __spreadArray(__spreadArray([], idSearchQuery, true), notesSearchQuery, true),
93
+ };
75
94
  return [4 /*yield*/, prisma.$transaction([
76
95
  prisma.lead.count({
77
96
  where: where,
@@ -79,13 +98,13 @@ var listLead = function (_a) { return __awaiter(void 0, [_a], void 0, function (
79
98
  prisma.lead.findMany({
80
99
  include: include,
81
100
  orderBy: orderBy,
82
- skip: skip,
101
+ skip: (currentPage - 1) * pageLimit,
83
102
  take: pageLimit,
84
103
  where: where,
85
104
  }),
86
105
  ])];
87
106
  case 1:
88
- _c = _j.sent(), count = _c[0], items = _c[1];
107
+ _c = _k.sent(), count = _c[0], items = _c[1];
89
108
  return [2 /*return*/, [count, items]];
90
109
  }
91
110
  });
@@ -97,7 +116,7 @@ exports.listLead = listLead;
97
116
  * @returns {Promise<LeadBE | null>} Lead or null if not found
98
117
  */
99
118
  var unitLeadById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
100
- var include, lead;
119
+ var include, where, lead;
101
120
  var id = _b.id, prisma = _b.prisma;
102
121
  return __generator(this, function (_c) {
103
122
  switch (_c.label) {
@@ -106,11 +125,12 @@ var unitLeadById = function (_a) { return __awaiter(void 0, [_a], void 0, functi
106
125
  throw new Error('Lead ID is required');
107
126
  }
108
127
  include = {};
128
+ where = {
129
+ id: id,
130
+ };
109
131
  return [4 /*yield*/, prisma.lead.findUnique({
110
132
  include: include,
111
- where: {
112
- id: id,
113
- },
133
+ where: where,
114
134
  })];
115
135
  case 1:
116
136
  lead = _c.sent();
@@ -125,7 +145,7 @@ exports.unitLeadById = unitLeadById;
125
145
  * @returns {Promise<LeadBE>} Updated lead
126
146
  */
127
147
  var updateLead = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
128
- var include, leadData, lead;
148
+ var leadData, where, lead;
129
149
  var id = _b.id, notes = _b.notes, prisma = _b.prisma, source = _b.source, status = _b.status, type = _b.type;
130
150
  return __generator(this, function (_c) {
131
151
  switch (_c.label) {
@@ -136,20 +156,19 @@ var updateLead = function (_a) { return __awaiter(void 0, [_a], void 0, function
136
156
  if (!notes || !source || !status || !type) {
137
157
  throw new Error('Notes, source, status, and type are required');
138
158
  }
139
- include = {};
140
159
  leadData = {
141
160
  notes: notes,
142
161
  source: source,
143
162
  status: status,
144
163
  type: type,
145
164
  };
165
+ where = {
166
+ id: id,
167
+ };
146
168
  return [4 /*yield*/, prisma.lead.upsert({
147
169
  create: __assign({ id: id }, leadData),
148
- include: include,
149
170
  update: leadData,
150
- where: {
151
- id: id,
152
- },
171
+ where: where,
153
172
  })];
154
173
  case 1:
155
174
  lead = _c.sent();
@@ -164,7 +183,7 @@ exports.updateLead = updateLead;
164
183
  * @returns {Promise<LeadBE>} Deleted lead
165
184
  */
166
185
  var deleteLead = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
167
- var include, lead;
186
+ var where, lead;
168
187
  var id = _b.id, prisma = _b.prisma;
169
188
  return __generator(this, function (_c) {
170
189
  switch (_c.label) {
@@ -172,12 +191,11 @@ var deleteLead = function (_a) { return __awaiter(void 0, [_a], void 0, function
172
191
  if (!id) {
173
192
  throw new Error('Lead ID is required');
174
193
  }
175
- include = {};
194
+ where = {
195
+ id: id,
196
+ };
176
197
  return [4 /*yield*/, prisma.lead.delete({
177
- include: include,
178
- where: {
179
- id: id,
180
- },
198
+ where: where,
181
199
  })];
182
200
  case 1:
183
201
  lead = _c.sent();
@@ -1,24 +1,27 @@
1
1
  import { MenuOrderBE } from '../type';
2
2
  type PrismaClient = any;
3
- interface ListMenuOrderArgs {
4
- currentPage: number;
3
+ export interface ListMenuOrderArgs {
4
+ currentPage?: number;
5
+ includePreference?: boolean;
5
6
  orderByColumn?: string;
6
7
  orderByDirection?: 'asc' | 'desc';
7
- pageLimit: number;
8
+ pageLimit?: number;
8
9
  prisma: PrismaClient;
10
+ searchQuery?: string;
9
11
  }
10
- interface UnitMenuOrderByIdArgs {
12
+ export interface UnitMenuOrderByIdArgs {
11
13
  id: string;
14
+ includePreference?: boolean;
12
15
  prisma: PrismaClient;
13
16
  }
14
- interface UpdateMenuOrderArgs {
17
+ export interface UpdateMenuOrderArgs {
15
18
  id: string;
16
19
  label: string;
17
20
  order: number;
18
21
  preferenceId: string;
19
22
  prisma: PrismaClient;
20
23
  }
21
- interface DeleteMenuOrderArgs {
24
+ export interface DeleteMenuOrderArgs {
22
25
  id: string;
23
26
  prisma: PrismaClient;
24
27
  }
@@ -27,13 +30,13 @@ interface DeleteMenuOrderArgs {
27
30
  * @param {ListMenuOrderArgs} args - Object containing prisma client and pagination parameters
28
31
  * @returns {Promise<[number, Array<MenuOrderBE>]>} Tuple of total count and menu orders array
29
32
  */
30
- export declare const listMenuOrder: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, }: ListMenuOrderArgs) => Promise<[number, Array<MenuOrderBE>]>;
33
+ export declare const listMenuOrder: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListMenuOrderArgs) => Promise<[number, Array<MenuOrderBE>]>;
31
34
  /**
32
35
  * Retrieves a single menu order by ID
33
36
  * @param {UnitMenuOrderByIdArgs} args - Object containing prisma client and menu order id
34
37
  * @returns {Promise<MenuOrderBE | null>} Menu order if found, null otherwise
35
38
  */
36
- export declare const unitMenuOrderById: ({ id, prisma, }: UnitMenuOrderByIdArgs) => Promise<MenuOrderBE | null>;
39
+ export declare const unitMenuOrderById: ({ id, includePreference, prisma, }: UnitMenuOrderByIdArgs) => Promise<MenuOrderBE | null>;
37
40
  /**
38
41
  * Updates an existing menu order
39
42
  * @param {UpdateMenuOrderArgs} args - Object containing prisma client and menu order data
@@ -46,19 +46,29 @@ 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.deleteMenuOrder = exports.updateMenuOrder = exports.unitMenuOrderById = exports.listMenuOrder = void 0;
60
+ var multi_part_search_1 = require("../../../general/multi-part-search");
51
61
  /**
52
62
  * Retrieves paginated menu orders with count
53
63
  * @param {ListMenuOrderArgs} args - Object containing prisma client and pagination parameters
54
64
  * @returns {Promise<[number, Array<MenuOrderBE>]>} Tuple of total count and menu orders array
55
65
  */
56
66
  var listMenuOrder = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var skip, _c, count, menuOrders;
67
+ var orderBy, idSearchQuery, labelSearchQuery, where, _c, count, items;
58
68
  var _d;
59
- var currentPage = _b.currentPage, _e = _b.orderByColumn, orderByColumn = _e === void 0 ? 'createdAt' : _e, _f = _b.orderByDirection, orderByDirection = _f === void 0 ? 'desc' : _f, pageLimit = _b.pageLimit, prisma = _b.prisma;
60
- return __generator(this, function (_g) {
61
- switch (_g.label) {
69
+ var _e = _b.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _b.orderByColumn, orderByColumn = _f === void 0 ? 'createdAt' : _f, _g = _b.orderByDirection, orderByDirection = _g === void 0 ? 'desc' : _g, _h = _b.pageLimit, pageLimit = _h === void 0 ? 1 : _h, prisma = _b.prisma, _j = _b.searchQuery, searchQuery = _j === void 0 ? '' : _j;
70
+ return __generator(this, function (_k) {
71
+ switch (_k.label) {
62
72
  case 0:
63
73
  if (currentPage < 1) {
64
74
  throw new Error('Current page must be greater than 0');
@@ -66,20 +76,34 @@ var listMenuOrder = function (_a) { return __awaiter(void 0, [_a], void 0, funct
66
76
  if (pageLimit < 1) {
67
77
  throw new Error('Page limit must be greater than 0');
68
78
  }
69
- skip = (currentPage - 1) * pageLimit;
79
+ orderBy = (_d = {},
80
+ _d[orderByColumn] = orderByDirection,
81
+ _d);
82
+ idSearchQuery = (0, multi_part_search_1.multiPartSearch)({
83
+ columnName: 'id',
84
+ fullText: searchQuery,
85
+ });
86
+ labelSearchQuery = (0, multi_part_search_1.multiPartSearch)({
87
+ columnName: 'label',
88
+ fullText: searchQuery,
89
+ });
90
+ where = {
91
+ OR: __spreadArray(__spreadArray([], idSearchQuery, true), labelSearchQuery, true),
92
+ };
70
93
  return [4 /*yield*/, prisma.$transaction([
71
- prisma.menuOrder.count(),
94
+ prisma.menuOrder.count({
95
+ where: where,
96
+ }),
72
97
  prisma.menuOrder.findMany({
73
- orderBy: (_d = {},
74
- _d[orderByColumn] = orderByDirection,
75
- _d),
76
- skip: skip,
98
+ orderBy: orderBy,
99
+ skip: (currentPage - 1) * pageLimit,
77
100
  take: pageLimit,
101
+ where: where,
78
102
  }),
79
103
  ])];
80
104
  case 1:
81
- _c = _g.sent(), count = _c[0], menuOrders = _c[1];
82
- return [2 /*return*/, [count, menuOrders]];
105
+ _c = _k.sent(), count = _c[0], items = _c[1];
106
+ return [2 /*return*/, [count, items]];
83
107
  }
84
108
  });
85
109
  }); };
@@ -90,21 +114,26 @@ exports.listMenuOrder = listMenuOrder;
90
114
  * @returns {Promise<MenuOrderBE | null>} Menu order if found, null otherwise
91
115
  */
92
116
  var unitMenuOrderById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
93
- var menuOrder;
94
- var id = _b.id, prisma = _b.prisma;
95
- return __generator(this, function (_c) {
96
- switch (_c.label) {
117
+ var include, where, menuOrder;
118
+ var id = _b.id, _c = _b.includePreference, includePreference = _c === void 0 ? false : _c, prisma = _b.prisma;
119
+ return __generator(this, function (_d) {
120
+ switch (_d.label) {
97
121
  case 0:
98
122
  if (!id) {
99
123
  throw new Error('Menu order ID is required');
100
124
  }
125
+ include = {
126
+ preference: includePreference,
127
+ };
128
+ where = {
129
+ id: id,
130
+ };
101
131
  return [4 /*yield*/, prisma.menuOrder.findUnique({
102
- where: {
103
- id: id,
104
- },
132
+ include: include,
133
+ where: where,
105
134
  })];
106
135
  case 1:
107
- menuOrder = _c.sent();
136
+ menuOrder = _d.sent();
108
137
  return [2 /*return*/, menuOrder];
109
138
  }
110
139
  });
@@ -116,7 +145,7 @@ exports.unitMenuOrderById = unitMenuOrderById;
116
145
  * @returns {Promise<MenuOrderBE>} Updated menu order
117
146
  */
118
147
  var updateMenuOrder = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
119
- var menuOrderData, menuOrder;
148
+ var menuOrderData, where, menuOrder;
120
149
  var id = _b.id, label = _b.label, order = _b.order, preferenceId = _b.preferenceId, prisma = _b.prisma;
121
150
  return __generator(this, function (_c) {
122
151
  switch (_c.label) {
@@ -132,12 +161,11 @@ var updateMenuOrder = function (_a) { return __awaiter(void 0, [_a], void 0, fun
132
161
  order: order,
133
162
  preferenceId: preferenceId,
134
163
  };
164
+ where = { id: id };
135
165
  return [4 /*yield*/, prisma.menuOrder.upsert({
136
- where: {
137
- id: id,
138
- },
139
- update: menuOrderData,
140
166
  create: __assign({ id: id }, menuOrderData),
167
+ update: menuOrderData,
168
+ where: where,
141
169
  })];
142
170
  case 1:
143
171
  menuOrder = _c.sent();
@@ -153,7 +181,7 @@ exports.updateMenuOrder = updateMenuOrder;
153
181
  * @throws {Error} If menu order ID is not provided or menu order not found
154
182
  */
155
183
  var deleteMenuOrder = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
156
- var menuOrder;
184
+ var where, menuOrder;
157
185
  var id = _b.id, prisma = _b.prisma;
158
186
  return __generator(this, function (_c) {
159
187
  switch (_c.label) {
@@ -161,10 +189,9 @@ var deleteMenuOrder = function (_a) { return __awaiter(void 0, [_a], void 0, fun
161
189
  if (!id) {
162
190
  throw new Error('Menu order ID is required');
163
191
  }
192
+ where = { id: id };
164
193
  return [4 /*yield*/, prisma.menuOrder.delete({
165
- where: {
166
- id: id,
167
- },
194
+ where: where,
168
195
  })];
169
196
  case 1:
170
197
  menuOrder = _c.sent();
@@ -1,6 +1,6 @@
1
1
  import { PaymentBE } from '../type';
2
2
  type PrismaClient = any;
3
- interface ListPaymentArgs {
3
+ export interface ListPaymentArgs {
4
4
  currentPage?: number;
5
5
  includePaymentMode?: boolean;
6
6
  includeQuoteInvoice?: boolean;
@@ -8,14 +8,15 @@ interface ListPaymentArgs {
8
8
  orderByDirection?: 'asc' | 'desc';
9
9
  pageLimit?: number;
10
10
  prisma: PrismaClient;
11
+ searchQuery?: string;
11
12
  }
12
- interface UnitPaymentByIdArgs {
13
+ export interface UnitPaymentByIdArgs {
13
14
  id: string;
14
15
  includePaymentMode?: boolean;
15
16
  includeQuoteInvoice?: boolean;
16
17
  prisma: PrismaClient;
17
18
  }
18
- interface UpdatePaymentArgs {
19
+ export interface UpdatePaymentArgs {
19
20
  amount: string;
20
21
  attachment?: string | null;
21
22
  balance?: string | null;
@@ -31,18 +32,18 @@ interface UpdatePaymentArgs {
31
32
  quoteInvoiceId: string;
32
33
  ref?: string | null;
33
34
  }
34
- interface DeletePaymentArgs {
35
+ export interface DeletePaymentArgs {
35
36
  id: string;
37
+ prisma: PrismaClient;
36
38
  includePaymentMode?: boolean;
37
39
  includeQuoteInvoice?: boolean;
38
- prisma: PrismaClient;
39
40
  }
40
41
  /**
41
42
  * Retrieves a paginated list of payments
42
43
  * @param {ListPaymentArgs} args - Object containing prisma client, pagination, filtering, and ordering options
43
44
  * @returns {Promise<[number, Array<PaymentBE>]>} Tuple containing total count and array of payments
44
45
  */
45
- export declare const listPayment: ({ currentPage, includePaymentMode, includeQuoteInvoice, orderByColumn, orderByDirection, pageLimit, prisma, }: ListPaymentArgs) => Promise<[number, Array<PaymentBE>]>;
46
+ export declare const listPayment: ({ currentPage, includePaymentMode, includeQuoteInvoice, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListPaymentArgs) => Promise<[number, Array<PaymentBE>]>;
46
47
  /**
47
48
  * Retrieves a single payment by its ID
48
49
  * @param {UnitPaymentByIdArgs} args - Object containing prisma client, payment ID, and optional query parameters
@@ -54,11 +55,11 @@ export declare const unitPaymentById: ({ id, includePaymentMode, includeQuoteInv
54
55
  * @param {UpdatePaymentArgs} args - Object containing prisma client and payment data
55
56
  * @returns {Promise<PaymentBE>} Updated payment
56
57
  */
57
- export declare const updatePayment: ({ amount, attachment, balance, currency, date, description, id, includePaymentMode, includeQuoteInvoice, paymentModeId, paymentType, prisma, quoteInvoiceId, ref, }: UpdatePaymentArgs) => Promise<PaymentBE>;
58
+ export declare const updatePayment: ({ amount, attachment, balance, currency, date, description, id, paymentModeId, paymentType, prisma, quoteInvoiceId, ref, }: UpdatePaymentArgs) => Promise<PaymentBE>;
58
59
  /**
59
60
  * Deletes a payment by ID
60
61
  * @param {DeletePaymentArgs} args - Object containing prisma client and payment ID
61
62
  * @returns {Promise<PaymentBE>} Deleted payment
62
63
  */
63
- export declare const deletePayment: ({ id, includePaymentMode, includeQuoteInvoice, prisma, }: DeletePaymentArgs) => Promise<PaymentBE>;
64
+ export declare const deletePayment: ({ id, prisma, }: DeletePaymentArgs) => Promise<PaymentBE>;
64
65
  export {};
@@ -46,25 +46,36 @@ 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.deletePayment = exports.updatePayment = exports.unitPaymentById = exports.listPayment = void 0;
60
+ var general_1 = require("../../../general");
61
+ var type_1 = require("../type");
51
62
  /**
52
63
  * Retrieves a paginated list of payments
53
64
  * @param {ListPaymentArgs} args - Object containing prisma client, pagination, filtering, and ordering options
54
65
  * @returns {Promise<[number, Array<PaymentBE>]>} Tuple containing total count and array of payments
55
66
  */
56
67
  var listPayment = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var include, orderBy, skip, where, _c, count, items;
68
+ var include, orderBy, idSearchQuery, descriptionSearchQuery, refSearchQuery, where, _c, count, items;
58
69
  var _d;
59
- var _e = _b.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _b.includePaymentMode, includePaymentMode = _f === void 0 ? false : _f, _g = _b.includeQuoteInvoice, includeQuoteInvoice = _g === void 0 ? false : _g, _h = _b.orderByColumn, orderByColumn = _h === void 0 ? 'createdAt' : _h, _j = _b.orderByDirection, orderByDirection = _j === void 0 ? 'desc' : _j, _k = _b.pageLimit, pageLimit = _k === void 0 ? 10 : _k, prisma = _b.prisma;
60
- return __generator(this, function (_l) {
61
- switch (_l.label) {
70
+ var _e = _b.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _b.includePaymentMode, includePaymentMode = _f === void 0 ? false : _f, _g = _b.includeQuoteInvoice, includeQuoteInvoice = _g === void 0 ? false : _g, _h = _b.orderByColumn, orderByColumn = _h === void 0 ? 'createdAt' : _h, _j = _b.orderByDirection, orderByDirection = _j === void 0 ? 'desc' : _j, _k = _b.pageLimit, pageLimit = _k === void 0 ? 5 : _k, prisma = _b.prisma, _l = _b.searchQuery, searchQuery = _l === void 0 ? '' : _l;
71
+ return __generator(this, function (_m) {
72
+ switch (_m.label) {
62
73
  case 0:
63
- if (currentPage < 1) {
64
- throw new Error('Current page must be greater than or equal to 1');
74
+ if (!currentPage || currentPage < 1) {
75
+ throw new Error('Valid current page is required');
65
76
  }
66
- if (pageLimit < 1) {
67
- throw new Error('Page limit must be greater than or equal to 1');
77
+ if (!pageLimit || pageLimit < 1) {
78
+ throw new Error('Valid page limit is required');
68
79
  }
69
80
  include = {
70
81
  paymentMode: includePaymentMode,
@@ -73,8 +84,21 @@ var listPayment = function (_a) { return __awaiter(void 0, [_a], void 0, functio
73
84
  orderBy = (_d = {},
74
85
  _d[orderByColumn] = orderByDirection,
75
86
  _d);
76
- skip = (currentPage - 1) * pageLimit;
77
- where = {};
87
+ idSearchQuery = (0, general_1.multiPartSearch)({
88
+ columnName: 'id',
89
+ fullText: searchQuery,
90
+ });
91
+ descriptionSearchQuery = (0, general_1.multiPartSearch)({
92
+ columnName: 'description',
93
+ fullText: searchQuery,
94
+ });
95
+ refSearchQuery = (0, general_1.multiPartSearch)({
96
+ columnName: 'ref',
97
+ fullText: searchQuery,
98
+ });
99
+ where = {
100
+ OR: __spreadArray(__spreadArray(__spreadArray([], idSearchQuery, true), descriptionSearchQuery, true), refSearchQuery, true),
101
+ };
78
102
  return [4 /*yield*/, prisma.$transaction([
79
103
  prisma.payment.count({
80
104
  where: where,
@@ -82,13 +106,13 @@ var listPayment = function (_a) { return __awaiter(void 0, [_a], void 0, functio
82
106
  prisma.payment.findMany({
83
107
  include: include,
84
108
  orderBy: orderBy,
85
- skip: skip,
109
+ skip: (currentPage - 1) * pageLimit,
86
110
  take: pageLimit,
87
111
  where: where,
88
112
  }),
89
113
  ])];
90
114
  case 1:
91
- _c = _l.sent(), count = _c[0], items = _c[1];
115
+ _c = _m.sent(), count = _c[0], items = _c[1];
92
116
  return [2 /*return*/, [count, items]];
93
117
  }
94
118
  });
@@ -100,7 +124,7 @@ exports.listPayment = listPayment;
100
124
  * @returns {Promise<PaymentBE | null>} Payment or null if not found
101
125
  */
102
126
  var unitPaymentById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
103
- var include, payment;
127
+ var include, where, payment;
104
128
  var id = _b.id, _c = _b.includePaymentMode, includePaymentMode = _c === void 0 ? false : _c, _d = _b.includeQuoteInvoice, includeQuoteInvoice = _d === void 0 ? false : _d, prisma = _b.prisma;
105
129
  return __generator(this, function (_e) {
106
130
  switch (_e.label) {
@@ -112,9 +136,10 @@ var unitPaymentById = function (_a) { return __awaiter(void 0, [_a], void 0, fun
112
136
  paymentMode: includePaymentMode,
113
137
  quoteInvoice: includeQuoteInvoice,
114
138
  };
139
+ where = { id: id };
115
140
  return [4 /*yield*/, prisma.payment.findUnique({
116
141
  include: include,
117
- where: { id: id },
142
+ where: where,
118
143
  })];
119
144
  case 1:
120
145
  payment = _e.sent();
@@ -129,10 +154,10 @@ exports.unitPaymentById = unitPaymentById;
129
154
  * @returns {Promise<PaymentBE>} Updated payment
130
155
  */
131
156
  var updatePayment = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
132
- var include, paymentData, payment;
133
- var amount = _b.amount, attachment = _b.attachment, balance = _b.balance, currency = _b.currency, date = _b.date, description = _b.description, id = _b.id, _c = _b.includePaymentMode, includePaymentMode = _c === void 0 ? false : _c, _d = _b.includeQuoteInvoice, includeQuoteInvoice = _d === void 0 ? false : _d, paymentModeId = _b.paymentModeId, paymentType = _b.paymentType, prisma = _b.prisma, quoteInvoiceId = _b.quoteInvoiceId, ref = _b.ref;
134
- return __generator(this, function (_e) {
135
- switch (_e.label) {
157
+ var paymentData, where, payment;
158
+ var amount = _b.amount, attachment = _b.attachment, balance = _b.balance, currency = _b.currency, date = _b.date, description = _b.description, id = _b.id, paymentModeId = _b.paymentModeId, paymentType = _b.paymentType, prisma = _b.prisma, quoteInvoiceId = _b.quoteInvoiceId, ref = _b.ref;
159
+ return __generator(this, function (_c) {
160
+ switch (_c.label) {
136
161
  case 0:
137
162
  if (!id) {
138
163
  throw new Error('Payment ID is required');
@@ -145,10 +170,6 @@ var updatePayment = function (_a) { return __awaiter(void 0, [_a], void 0, funct
145
170
  !quoteInvoiceId) {
146
171
  throw new Error('Amount, currency, date, payment mode ID, payment type, and quote invoice ID are required');
147
172
  }
148
- include = {
149
- paymentMode: includePaymentMode,
150
- quoteInvoice: includeQuoteInvoice,
151
- };
152
173
  paymentData = {
153
174
  amount: amount,
154
175
  attachment: attachment || null,
@@ -161,22 +182,22 @@ var updatePayment = function (_a) { return __awaiter(void 0, [_a], void 0, funct
161
182
  quoteInvoiceId: quoteInvoiceId,
162
183
  ref: ref || null,
163
184
  };
185
+ where = { id: id };
164
186
  return [4 /*yield*/, prisma.payment.upsert({
165
187
  create: __assign({ id: id }, paymentData),
166
- include: include,
167
188
  update: paymentData,
168
- where: { id: id },
189
+ where: where,
169
190
  })];
170
191
  case 1:
171
- payment = _e.sent();
192
+ payment = _c.sent();
172
193
  if (!(Number(balance) === 0)) return [3 /*break*/, 3];
173
194
  return [4 /*yield*/, prisma.quoteInvoice.update({
174
- data: { invoiceStatus: 'PAID' },
195
+ data: { invoiceStatus: type_1.INVOICE_STATUS.PAID },
175
196
  where: { id: quoteInvoiceId },
176
197
  })];
177
198
  case 2:
178
- _e.sent();
179
- _e.label = 3;
199
+ _c.sent();
200
+ _c.label = 3;
180
201
  case 3: return [2 /*return*/, payment];
181
202
  }
182
203
  });
@@ -188,24 +209,20 @@ exports.updatePayment = updatePayment;
188
209
  * @returns {Promise<PaymentBE>} Deleted payment
189
210
  */
190
211
  var deletePayment = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
191
- var include, payment;
192
- var id = _b.id, _c = _b.includePaymentMode, includePaymentMode = _c === void 0 ? false : _c, _d = _b.includeQuoteInvoice, includeQuoteInvoice = _d === void 0 ? false : _d, prisma = _b.prisma;
193
- return __generator(this, function (_e) {
194
- switch (_e.label) {
212
+ var where, payment;
213
+ var id = _b.id, prisma = _b.prisma;
214
+ return __generator(this, function (_c) {
215
+ switch (_c.label) {
195
216
  case 0:
196
217
  if (!id) {
197
218
  throw new Error('Payment ID is required');
198
219
  }
199
- include = {
200
- paymentMode: includePaymentMode,
201
- quoteInvoice: includeQuoteInvoice,
202
- };
220
+ where = { id: id };
203
221
  return [4 /*yield*/, prisma.payment.delete({
204
- include: include,
205
- where: { id: id },
222
+ where: where,
206
223
  })];
207
224
  case 1:
208
- payment = _e.sent();
225
+ payment = _c.sent();
209
226
  return [2 /*return*/, payment];
210
227
  }
211
228
  });