@react-pakistan/util-functions 1.24.69 → 1.24.70

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.
@@ -6,6 +6,7 @@ interface ListCompanyArgs {
6
6
  orderByDirection?: 'asc' | 'desc';
7
7
  pageLimit: number;
8
8
  prisma: PrismaClient;
9
+ searchQuery?: string;
9
10
  }
10
11
  interface UnitCompanyByIdArgs {
11
12
  id: string;
@@ -29,7 +30,7 @@ interface DeleteCompanyArgs {
29
30
  * @param {ListCompanyArgs} args - Object containing prisma client, pagination, and filter options
30
31
  * @returns {Promise<[number, Array<CompanyBE>]>} Tuple of [total count, array of companies]
31
32
  */
32
- export declare const listCompany: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, }: ListCompanyArgs) => Promise<[number, Array<CompanyBE>]>;
33
+ export declare const listCompany: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListCompanyArgs) => Promise<[number, Array<CompanyBE>]>;
33
34
  /**
34
35
  * Retrieves a single company by ID
35
36
  * @param {UnitCompanyByIdArgs} args - Object containing prisma client and company id
@@ -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;
67
+ var idSearchQuery, nameSearchQuery, emailSearchQuery, where, companies;
58
68
  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) {
69
+ 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, _f = _b.searchQuery, searchQuery = _f === void 0 ? '' : _f;
70
+ return __generator(this, function (_g) {
71
+ switch (_g.label) {
62
72
  case 0:
63
73
  if (!currentPage || currentPage < 1) {
64
74
  throw new Error('Valid current page is required');
@@ -66,18 +76,36 @@ 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
+ idSearchQuery = (0, multi_part_search_1.multiPartSearch)({
80
+ columnName: 'id',
81
+ fullText: searchQuery,
82
+ });
83
+ nameSearchQuery = (0, multi_part_search_1.multiPartSearch)({
84
+ columnName: 'name',
85
+ fullText: searchQuery,
86
+ });
87
+ emailSearchQuery = (0, multi_part_search_1.multiPartSearch)({
88
+ columnName: 'email',
89
+ fullText: searchQuery,
90
+ });
91
+ where = {
92
+ OR: __spreadArray(__spreadArray(__spreadArray([], idSearchQuery, true), nameSearchQuery, true), emailSearchQuery, true),
93
+ };
69
94
  return [4 /*yield*/, prisma.$transaction([
70
- prisma.company.count(),
95
+ prisma.company.count({
96
+ where: where,
97
+ }),
71
98
  prisma.company.findMany({
72
99
  orderBy: (_c = {},
73
100
  _c[orderByColumn] = orderByDirection,
74
101
  _c),
75
102
  skip: (currentPage - 1) * pageLimit,
76
103
  take: pageLimit,
104
+ where: where,
77
105
  }),
78
106
  ])];
79
107
  case 1:
80
- companies = _f.sent();
108
+ companies = _g.sent();
81
109
  return [2 /*return*/, companies];
82
110
  }
83
111
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.24.69",
3
+ "version": "1.24.70",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {