@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.
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 +13 -8
  8. package/api/stellar-solutions/company/index.js +70 -28
  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
@@ -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.deleteCompany = exports.updateCompany = exports.unitCompanyById = exports.listCompany = void 0;
60
+ var multi_part_search_1 = require("../../../general/multi-part-search");
51
61
  /**
52
62
  * Retrieves all companies from the database with pagination
53
63
  * @param {ListCompanyArgs} args - Object containing prisma client, pagination, and filter options
54
64
  * @returns {Promise<[number, Array<CompanyBE>]>} Tuple of [total count, array of companies]
55
65
  */
56
66
  var listCompany = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var companies;
58
- var _c;
59
- var currentPage = _b.currentPage, _d = _b.orderByColumn, orderByColumn = _d === void 0 ? 'createdAt' : _d, _e = _b.orderByDirection, orderByDirection = _e === void 0 ? 'desc' : _e, pageLimit = _b.pageLimit, prisma = _b.prisma;
60
- return __generator(this, function (_f) {
61
- switch (_f.label) {
67
+ var include, orderBy, idSearchQuery, nameSearchQuery, emailSearchQuery, where, _c, count, items;
68
+ var _d;
69
+ var _e = _b.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _b.includeContacts, includeContacts = _f === void 0 ? false : _f, _g = _b.includeQuotesInvoices, includeQuotesInvoices = _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;
70
+ return __generator(this, function (_m) {
71
+ switch (_m.label) {
62
72
  case 0:
63
73
  if (!currentPage || currentPage < 1) {
64
74
  throw new Error('Valid current page is required');
@@ -66,19 +76,43 @@ var listCompany = function (_a) { return __awaiter(void 0, [_a], void 0, functio
66
76
  if (!pageLimit || pageLimit < 1) {
67
77
  throw new Error('Valid page limit is required');
68
78
  }
79
+ include = {
80
+ contacts: includeContacts,
81
+ quotesInvoices: includeQuotesInvoices,
82
+ };
83
+ orderBy = (_d = {},
84
+ _d[orderByColumn] = orderByDirection,
85
+ _d);
86
+ idSearchQuery = (0, multi_part_search_1.multiPartSearch)({
87
+ columnName: 'id',
88
+ fullText: searchQuery,
89
+ });
90
+ nameSearchQuery = (0, multi_part_search_1.multiPartSearch)({
91
+ columnName: 'name',
92
+ fullText: searchQuery,
93
+ });
94
+ emailSearchQuery = (0, multi_part_search_1.multiPartSearch)({
95
+ columnName: 'email',
96
+ fullText: searchQuery,
97
+ });
98
+ where = {
99
+ OR: __spreadArray(__spreadArray(__spreadArray([], idSearchQuery, true), nameSearchQuery, true), emailSearchQuery, true),
100
+ };
69
101
  return [4 /*yield*/, prisma.$transaction([
70
- prisma.company.count(),
102
+ prisma.company.count({
103
+ where: where,
104
+ }),
71
105
  prisma.company.findMany({
72
- orderBy: (_c = {},
73
- _c[orderByColumn] = orderByDirection,
74
- _c),
106
+ include: include,
107
+ orderBy: orderBy,
75
108
  skip: (currentPage - 1) * pageLimit,
76
109
  take: pageLimit,
110
+ where: where,
77
111
  }),
78
112
  ])];
79
113
  case 1:
80
- companies = _f.sent();
81
- return [2 /*return*/, companies];
114
+ _c = _m.sent(), count = _c[0], items = _c[1];
115
+ return [2 /*return*/, [count, items]];
82
116
  }
83
117
  });
84
118
  }); };
@@ -89,21 +123,27 @@ exports.listCompany = listCompany;
89
123
  * @returns {Promise<CompanyBE | null>} Company if found, null otherwise
90
124
  */
91
125
  var unitCompanyById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
92
- var company;
93
- var id = _b.id, prisma = _b.prisma;
94
- return __generator(this, function (_c) {
95
- switch (_c.label) {
126
+ var include, where, company;
127
+ var id = _b.id, _c = _b.includeContacts, includeContacts = _c === void 0 ? false : _c, _d = _b.includeQuotesInvoices, includeQuotesInvoices = _d === void 0 ? false : _d, prisma = _b.prisma;
128
+ return __generator(this, function (_e) {
129
+ switch (_e.label) {
96
130
  case 0:
97
131
  if (!id) {
98
132
  throw new Error('Company ID is required');
99
133
  }
134
+ include = {
135
+ contacts: includeContacts,
136
+ quotesInvoices: includeQuotesInvoices,
137
+ };
138
+ where = {
139
+ id: id,
140
+ };
100
141
  return [4 /*yield*/, prisma.company.findUnique({
101
- where: {
102
- id: id,
103
- },
142
+ include: include,
143
+ where: where,
104
144
  })];
105
145
  case 1:
106
- company = _c.sent();
146
+ company = _e.sent();
107
147
  return [2 /*return*/, company];
108
148
  }
109
149
  });
@@ -115,7 +155,7 @@ exports.unitCompanyById = unitCompanyById;
115
155
  * @returns {Promise<CompanyBE>} Created or updated company
116
156
  */
117
157
  var updateCompany = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
118
- var companyData, company;
158
+ var companyData, where, company;
119
159
  var country = _b.country, email = _b.email, id = _b.id, name = _b.name, phone = _b.phone, prisma = _b.prisma, website = _b.website;
120
160
  return __generator(this, function (_c) {
121
161
  switch (_c.label) {
@@ -133,12 +173,13 @@ var updateCompany = function (_a) { return __awaiter(void 0, [_a], void 0, funct
133
173
  phone: phone,
134
174
  website: website || null,
135
175
  };
176
+ where = {
177
+ id: id,
178
+ };
136
179
  return [4 /*yield*/, prisma.company.upsert({
137
- where: {
138
- id: id,
139
- },
140
- update: companyData,
141
180
  create: __assign({ id: id }, companyData),
181
+ update: companyData,
182
+ where: where,
142
183
  })];
143
184
  case 1:
144
185
  company = _c.sent();
@@ -154,7 +195,7 @@ exports.updateCompany = updateCompany;
154
195
  * @throws {Error} If company ID is not provided or company not found
155
196
  */
156
197
  var deleteCompany = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
157
- var company;
198
+ var where, company;
158
199
  var id = _b.id, prisma = _b.prisma;
159
200
  return __generator(this, function (_c) {
160
201
  switch (_c.label) {
@@ -162,10 +203,11 @@ var deleteCompany = function (_a) { return __awaiter(void 0, [_a], void 0, funct
162
203
  if (!id) {
163
204
  throw new Error('Company ID is required');
164
205
  }
206
+ where = {
207
+ id: id,
208
+ };
165
209
  return [4 /*yield*/, prisma.company.delete({
166
- where: {
167
- id: id,
168
- },
210
+ where: where,
169
211
  })];
170
212
  case 1:
171
213
  company = _c.sent();
@@ -1,6 +1,6 @@
1
1
  import { CompanyBE } from '../type';
2
2
  type PrismaClient = any;
3
- interface PostCompaniesReportArgs {
3
+ export interface PostCompaniesReportArgs {
4
4
  orderByColumn?: string;
5
5
  orderByDirection?: 'asc' | 'desc';
6
6
  prisma: PrismaClient;
@@ -1,17 +1,20 @@
1
1
  import { ContactBE } from '../type';
2
2
  type PrismaClient = any;
3
- interface ListContactArgs {
4
- currentPage: number;
3
+ export interface ListContactArgs {
4
+ currentPage?: number;
5
+ includeCompany?: 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 UnitContactByIdArgs {
12
+ export interface UnitContactByIdArgs {
11
13
  id: string;
14
+ includeCompany?: boolean;
12
15
  prisma: PrismaClient;
13
16
  }
14
- interface UpdateContactArgs {
17
+ export interface UpdateContactArgs {
15
18
  companyId: string;
16
19
  country: string;
17
20
  email: string;
@@ -21,7 +24,7 @@ interface UpdateContactArgs {
21
24
  phone: string;
22
25
  prisma: PrismaClient;
23
26
  }
24
- interface DeleteContactArgs {
27
+ export interface DeleteContactArgs {
25
28
  id: string;
26
29
  prisma: PrismaClient;
27
30
  }
@@ -30,13 +33,13 @@ interface DeleteContactArgs {
30
33
  * @param {ListContactArgs} args - Object containing prisma client, pagination, and query options
31
34
  * @returns {Promise<[number, Array<ContactBE>]>} Tuple containing total count and array of contacts
32
35
  */
33
- export declare const listContact: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, }: ListContactArgs) => Promise<[number, Array<ContactBE>]>;
36
+ export declare const listContact: ({ currentPage, includeCompany, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListContactArgs) => Promise<[number, Array<ContactBE>]>;
34
37
  /**
35
38
  * Retrieves a single contact by ID
36
39
  * @param {UnitContactByIdArgs} args - Object containing prisma client and query where conditions
37
40
  * @returns {Promise<ContactBE | null>} Contact if found, null otherwise
38
41
  */
39
- export declare const unitContactById: ({ prisma, id, }: UnitContactByIdArgs) => Promise<ContactBE | null>;
42
+ export declare const unitContactById: ({ id, includeCompany, prisma, }: UnitContactByIdArgs) => Promise<ContactBE | null>;
40
43
  /**
41
44
  * Creates or updates a contact
42
45
  * @param {UpdateContactArgs} args - Object containing prisma client and contact data
@@ -49,5 +52,5 @@ export declare const updateContact: ({ prisma, id, companyId, country, email, fi
49
52
  * @returns {Promise<ContactBE>} Deleted contact
50
53
  * @throws {Error} If contact ID is not provided or contact not found
51
54
  */
52
- export declare const deleteContact: ({ prisma, id, }: DeleteContactArgs) => Promise<ContactBE>;
55
+ export declare const deleteContact: ({ id, prisma, }: DeleteContactArgs) => Promise<ContactBE>;
53
56
  export {};
@@ -46,37 +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.deleteContact = exports.updateContact = exports.unitContactById = exports.listContact = void 0;
60
+ var multi_part_search_1 = require("../../../general/multi-part-search");
51
61
  /**
52
62
  * Retrieves contacts with pagination and filtering
53
63
  * @param {ListContactArgs} args - Object containing prisma client, pagination, and query options
54
64
  * @returns {Promise<[number, Array<ContactBE>]>} Tuple containing total count and array of contacts
55
65
  */
56
66
  var listContact = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var _c, count, contacts;
67
+ var include, orderBy, idSearchQuery, firstNameSearchQuery, lastNameSearchQuery, emailSearchQuery, 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.includeCompany, includeCompany = _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
+ company: includeCompany,
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
+ where = {
102
+ OR: __spreadArray(__spreadArray(__spreadArray(__spreadArray([], idSearchQuery, true), firstNameSearchQuery, true), lastNameSearchQuery, true), emailSearchQuery, true),
103
+ };
69
104
  return [4 /*yield*/, prisma.$transaction([
70
- prisma.contact.count(),
105
+ prisma.contact.count({
106
+ where: where,
107
+ }),
71
108
  prisma.contact.findMany({
72
- orderBy: (_d = {}, _d[orderByColumn] = orderByDirection, _d),
109
+ include: include,
110
+ orderBy: orderBy,
73
111
  take: pageLimit,
74
112
  skip: (currentPage - 1) * pageLimit,
113
+ where: where,
75
114
  }),
76
115
  ])];
77
116
  case 1:
78
- _c = _g.sent(), count = _c[0], contacts = _c[1];
79
- return [2 /*return*/, [count, contacts]];
117
+ _c = _l.sent(), count = _c[0], items = _c[1];
118
+ return [2 /*return*/, [count, items]];
80
119
  }
81
120
  });
82
121
  }); };
@@ -87,19 +126,26 @@ exports.listContact = listContact;
87
126
  * @returns {Promise<ContactBE | null>} Contact if found, null otherwise
88
127
  */
89
128
  var unitContactById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
90
- var contact;
91
- var prisma = _b.prisma, id = _b.id;
92
- return __generator(this, function (_c) {
93
- switch (_c.label) {
129
+ var include, where, contact;
130
+ var id = _b.id, _c = _b.includeCompany, includeCompany = _c === void 0 ? false : _c, prisma = _b.prisma;
131
+ return __generator(this, function (_d) {
132
+ switch (_d.label) {
94
133
  case 0:
95
134
  if (!id) {
96
135
  throw new Error('Contact ID is required');
97
136
  }
137
+ include = {
138
+ company: includeCompany,
139
+ };
140
+ where = {
141
+ id: id,
142
+ };
98
143
  return [4 /*yield*/, prisma.contact.findUnique({
99
- where: { id: id },
144
+ include: include,
145
+ where: where,
100
146
  })];
101
147
  case 1:
102
- contact = _c.sent();
148
+ contact = _d.sent();
103
149
  return [2 /*return*/, contact];
104
150
  }
105
151
  });
@@ -111,7 +157,7 @@ exports.unitContactById = unitContactById;
111
157
  * @returns {Promise<ContactBE>} Created or updated contact
112
158
  */
113
159
  var updateContact = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
114
- var contactData, contact;
160
+ var contactData, where, contact;
115
161
  var prisma = _b.prisma, id = _b.id, companyId = _b.companyId, country = _b.country, email = _b.email, firstName = _b.firstName, lastName = _b.lastName, phone = _b.phone;
116
162
  return __generator(this, function (_c) {
117
163
  switch (_c.label) {
@@ -130,10 +176,11 @@ var updateContact = function (_a) { return __awaiter(void 0, [_a], void 0, funct
130
176
  lastName: lastName,
131
177
  phone: phone,
132
178
  };
179
+ where = { id: id };
133
180
  return [4 /*yield*/, prisma.contact.upsert({
134
- where: { id: id },
135
- update: contactData,
136
181
  create: __assign({ id: id }, contactData),
182
+ update: contactData,
183
+ where: where,
137
184
  })];
138
185
  case 1:
139
186
  contact = _c.sent();
@@ -149,16 +196,17 @@ exports.updateContact = updateContact;
149
196
  * @throws {Error} If contact ID is not provided or contact not found
150
197
  */
151
198
  var deleteContact = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
152
- var contact;
153
- var prisma = _b.prisma, id = _b.id;
199
+ var where, contact;
200
+ var id = _b.id, prisma = _b.prisma;
154
201
  return __generator(this, function (_c) {
155
202
  switch (_c.label) {
156
203
  case 0:
157
204
  if (!id) {
158
205
  throw new Error('Contact ID is required');
159
206
  }
207
+ where = { id: id };
160
208
  return [4 /*yield*/, prisma.contact.delete({
161
- where: { id: id },
209
+ where: where,
162
210
  })];
163
211
  case 1:
164
212
  contact = _c.sent();
@@ -1,17 +1,20 @@
1
1
  import { CurrencyBE } from '../type';
2
2
  type PrismaClient = any;
3
- interface ListCurrencyArgs {
4
- currentPage: number;
3
+ export interface ListCurrencyArgs {
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 UnitCurrencyByIdArgs {
12
+ export interface UnitCurrencyByIdArgs {
11
13
  id: string;
14
+ includePreference?: boolean;
12
15
  prisma: PrismaClient;
13
16
  }
14
- interface UpdateCurrencyArgs {
17
+ export interface UpdateCurrencyArgs {
15
18
  code: string;
16
19
  enabled: boolean;
17
20
  id: string;
@@ -20,7 +23,7 @@ interface UpdateCurrencyArgs {
20
23
  preferenceId: string;
21
24
  prisma: PrismaClient;
22
25
  }
23
- interface DeleteCurrencyArgs {
26
+ export interface DeleteCurrencyArgs {
24
27
  id: string;
25
28
  prisma: PrismaClient;
26
29
  }
@@ -29,13 +32,13 @@ interface DeleteCurrencyArgs {
29
32
  * @param {ListCurrencyArgs} args - Object containing prisma client, pagination, and query options
30
33
  * @returns {Promise<[number, Array<CurrencyBE>]>} Tuple containing total count and array of currencies
31
34
  */
32
- export declare const listCurrency: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, }: ListCurrencyArgs) => Promise<[number, Array<CurrencyBE>]>;
35
+ export declare const listCurrency: ({ currentPage, includePreference, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListCurrencyArgs) => Promise<[number, Array<CurrencyBE>]>;
33
36
  /**
34
37
  * Retrieves a single currency by ID
35
38
  * @param {UnitCurrencyByIdArgs} args - Object containing prisma client and query where conditions
36
39
  * @returns {Promise<CurrencyBE | null>} Currency if found, null otherwise
37
40
  */
38
- export declare const unitCurrencyById: ({ id, prisma, }: UnitCurrencyByIdArgs) => Promise<CurrencyBE | null>;
41
+ export declare const unitCurrencyById: ({ id, includePreference, prisma, }: UnitCurrencyByIdArgs) => Promise<CurrencyBE | null>;
39
42
  /**
40
43
  * Creates or updates a currency
41
44
  * @param {UpdateCurrencyArgs} args - Object containing prisma client and currency data
@@ -46,40 +46,68 @@ 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.deleteCurrency = exports.updateCurrency = exports.unitCurrencyById = exports.listCurrency = void 0;
60
+ var multi_part_search_1 = require("../../../general/multi-part-search");
51
61
  /**
52
62
  * Retrieves currencies with pagination and filtering
53
63
  * @param {ListCurrencyArgs} args - Object containing prisma client, pagination, and query options
54
64
  * @returns {Promise<[number, Array<CurrencyBE>]>} Tuple containing total count and array of currencies
55
65
  */
56
66
  var listCurrency = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var skip, _c, count, currencies;
67
+ var orderBy, include, 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.includePreference, includePreference = _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
  }
69
- skip = (currentPage - 1) * pageLimit;
79
+ orderBy = (_d = {},
80
+ _d[orderByColumn] = orderByDirection,
81
+ _d);
82
+ include = {
83
+ preference: includePreference,
84
+ };
85
+ idSearchQuery = (0, multi_part_search_1.multiPartSearch)({
86
+ columnName: 'id',
87
+ fullText: searchQuery,
88
+ });
89
+ labelSearchQuery = (0, multi_part_search_1.multiPartSearch)({
90
+ columnName: 'label',
91
+ fullText: searchQuery,
92
+ });
93
+ where = {
94
+ OR: __spreadArray(__spreadArray([], idSearchQuery, true), labelSearchQuery, true),
95
+ };
70
96
  return [4 /*yield*/, prisma.$transaction([
71
- prisma.currency.count(),
97
+ prisma.currency.count({
98
+ where: where,
99
+ }),
72
100
  prisma.currency.findMany({
73
- orderBy: (_d = {},
74
- _d[orderByColumn] = orderByDirection,
75
- _d),
76
- skip: skip,
101
+ include: include,
102
+ orderBy: orderBy,
103
+ skip: (currentPage - 1) * pageLimit,
77
104
  take: pageLimit,
105
+ where: where,
78
106
  }),
79
107
  ])];
80
108
  case 1:
81
- _c = _g.sent(), count = _c[0], currencies = _c[1];
82
- return [2 /*return*/, [count, currencies]];
109
+ _c = _l.sent(), count = _c[0], items = _c[1];
110
+ return [2 /*return*/, [count, items]];
83
111
  }
84
112
  });
85
113
  }); };
@@ -90,21 +118,26 @@ exports.listCurrency = listCurrency;
90
118
  * @returns {Promise<CurrencyBE | null>} Currency if found, null otherwise
91
119
  */
92
120
  var unitCurrencyById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
93
- var currency;
94
- var id = _b.id, prisma = _b.prisma;
95
- return __generator(this, function (_c) {
96
- switch (_c.label) {
121
+ var include, where, currency;
122
+ var id = _b.id, _c = _b.includePreference, includePreference = _c === void 0 ? false : _c, prisma = _b.prisma;
123
+ return __generator(this, function (_d) {
124
+ switch (_d.label) {
97
125
  case 0:
98
126
  if (!id) {
99
127
  throw new Error('Currency ID is required');
100
128
  }
129
+ include = {
130
+ preference: includePreference,
131
+ };
132
+ where = {
133
+ id: id,
134
+ };
101
135
  return [4 /*yield*/, prisma.currency.findUnique({
102
- where: {
103
- id: id,
104
- },
136
+ include: include,
137
+ where: where,
105
138
  })];
106
139
  case 1:
107
- currency = _c.sent();
140
+ currency = _d.sent();
108
141
  return [2 /*return*/, currency];
109
142
  }
110
143
  });
@@ -116,7 +149,7 @@ exports.unitCurrencyById = unitCurrencyById;
116
149
  * @returns {Promise<CurrencyBE>} Created or updated currency
117
150
  */
118
151
  var updateCurrency = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
119
- var currencyData, currency;
152
+ var currencyData, where, currency;
120
153
  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;
121
154
  return __generator(this, function (_d) {
122
155
  switch (_d.label) {
@@ -134,12 +167,13 @@ var updateCurrency = function (_a) { return __awaiter(void 0, [_a], void 0, func
134
167
  label: label,
135
168
  preferenceId: preferenceId,
136
169
  };
170
+ where = {
171
+ id: id,
172
+ };
137
173
  return [4 /*yield*/, prisma.currency.upsert({
138
- where: {
139
- id: id,
140
- },
141
- update: currencyData,
142
174
  create: __assign({ id: id }, currencyData),
175
+ update: currencyData,
176
+ where: where,
143
177
  })];
144
178
  case 1:
145
179
  currency = _d.sent();
@@ -155,7 +189,7 @@ exports.updateCurrency = updateCurrency;
155
189
  * @throws {Error} If currency ID is not provided or currency not found
156
190
  */
157
191
  var deleteCurrency = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
158
- var currency;
192
+ var where, currency;
159
193
  var id = _b.id, prisma = _b.prisma;
160
194
  return __generator(this, function (_c) {
161
195
  switch (_c.label) {
@@ -163,10 +197,11 @@ var deleteCurrency = function (_a) { return __awaiter(void 0, [_a], void 0, func
163
197
  if (!id) {
164
198
  throw new Error('Currency ID is required');
165
199
  }
200
+ where = {
201
+ id: id,
202
+ };
166
203
  return [4 /*yield*/, prisma.currency.delete({
167
- where: {
168
- id: id,
169
- },
204
+ where: where,
170
205
  })];
171
206
  case 1:
172
207
  currency = _c.sent();