@react-pakistan/util-functions 1.24.65 → 1.24.67

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 (110) hide show
  1. package/README.md +6 -3
  2. package/api/stellar-solutions/app-user/index.d.ts +63 -14
  3. package/api/stellar-solutions/app-user/index.js +106 -52
  4. package/api/stellar-solutions/bank/index.d.ts +65 -16
  5. package/api/stellar-solutions/bank/index.js +115 -65
  6. package/api/stellar-solutions/branch/index.d.ts +64 -15
  7. package/api/stellar-solutions/branch/index.js +119 -65
  8. package/api/stellar-solutions/company/index.d.ts +58 -24
  9. package/api/stellar-solutions/company/index.js +106 -78
  10. package/api/stellar-solutions/company-report/index.d.ts +12 -5
  11. package/api/stellar-solutions/company-report/index.js +12 -7
  12. package/api/stellar-solutions/contact/index.d.ts +54 -20
  13. package/api/stellar-solutions/contact/index.js +109 -88
  14. package/api/stellar-solutions/currency/index.d.ts +63 -14
  15. package/api/stellar-solutions/currency/index.js +113 -61
  16. package/api/stellar-solutions/customer/index.d.ts +70 -28
  17. package/api/stellar-solutions/customer/index.js +131 -101
  18. package/api/stellar-solutions/expense/index.d.ts +58 -22
  19. package/api/stellar-solutions/expense/index.js +128 -92
  20. package/api/stellar-solutions/expense-category/index.d.ts +58 -22
  21. package/api/stellar-solutions/expense-category/index.js +125 -86
  22. package/api/stellar-solutions/lead/index.js +0 -1
  23. package/api/stellar-solutions/menu-order/index.d.ts +29 -7
  24. package/api/stellar-solutions/menu-order/index.js +74 -27
  25. package/api/stellar-solutions/payment/index.d.ts +62 -27
  26. package/api/stellar-solutions/payment/index.js +144 -123
  27. package/api/stellar-solutions/payment-mode/index.d.ts +44 -12
  28. package/api/stellar-solutions/payment-mode/index.js +115 -49
  29. package/api/stellar-solutions/preference/index.d.ts +14 -3
  30. package/api/stellar-solutions/preference/index.js +44 -14
  31. package/api/stellar-solutions/product/index.d.ts +48 -31
  32. package/api/stellar-solutions/product/index.js +153 -115
  33. package/api/stellar-solutions/product-category/index.d.ts +44 -27
  34. package/api/stellar-solutions/product-category/index.js +123 -87
  35. package/api/stellar-solutions/profile/index.d.ts +48 -17
  36. package/api/stellar-solutions/profile/index.js +124 -65
  37. package/api/stellar-solutions/quote-invoice/index.d.ts +67 -8
  38. package/api/stellar-solutions/quote-invoice/index.js +123 -57
  39. package/api/stellar-solutions/quote-invoice-report/index.d.ts +12 -5
  40. package/api/stellar-solutions/quote-invoice-report/index.js +10 -5
  41. package/api/stellar-solutions/tax/index.d.ts +46 -14
  42. package/api/stellar-solutions/tax/index.js +135 -63
  43. package/api/stellar-solutions/type.d.ts +178 -112
  44. package/api/stellar-solutions/type.js +60 -2
  45. package/constants/countries-timezones.js +0 -1
  46. package/constants/currencies.js +0 -1
  47. package/general/basic-get.js +22 -21
  48. package/general/basic-post.js +19 -18
  49. package/general/calculate-pages.js +3 -1
  50. package/general/check-even-odd-length.js +3 -2
  51. package/general/delete-image-from-private-supabase.js +0 -1
  52. package/general/delete-image-from-public-supabase.js +0 -1
  53. package/general/dynamic-page-limit.js +3 -2
  54. package/general/enum-to-text.js +7 -4
  55. package/general/fetch-data.js +0 -1
  56. package/general/fetch-supabase-image.js +0 -1
  57. package/general/fetch-supabase-private-assets.js +15 -14
  58. package/general/format-date.js +8 -8
  59. package/general/format-number.js +3 -2
  60. package/general/format-time.js +3 -2
  61. package/general/full-year-range.js +2 -2
  62. package/general/generate-blog-schema.d.ts +3 -3
  63. package/general/generate-blog-schema.js +20 -13
  64. package/general/generate-breadcrumb-schema.d.ts +4 -4
  65. package/general/generate-breadcrumb-schema.js +9 -10
  66. package/general/generate-faq-schema.d.ts +5 -5
  67. package/general/generate-faq-schema.js +18 -11
  68. package/general/generate-grid.js +0 -1
  69. package/general/generate-organization-schema.d.ts +3 -3
  70. package/general/generate-organization-schema.js +25 -18
  71. package/general/get-available-page-limit.js +2 -2
  72. package/general/get-calendar-dates.js +14 -3
  73. package/general/get-full-name.d.ts +1 -1
  74. package/general/get-number-of-days-in-month.d.ts +1 -1
  75. package/general/get-pathname.js +4 -1
  76. package/general/is-odd.js +1 -1
  77. package/general/is-previous-button-disabled.js +3 -1
  78. package/general/parse-frontmatter.js +0 -1
  79. package/general/remove-data-image-prefix.js +3 -2
  80. package/general/repeat-times.js +0 -1
  81. package/general/resolve-current-date.js +1 -2
  82. package/general/resolve-grid.js +3 -2
  83. package/general/slugify.js +11 -9
  84. package/general/text-to-enum.js +6 -1
  85. package/general/text-to-sentence-case.js +3 -1
  86. package/general/time-out.js +5 -4
  87. package/general/truncate-text.js +3 -1
  88. package/general/upload-blob-to-private-supabase.js +2 -2
  89. package/general/upload-blob-to-public-supabase.js +2 -2
  90. package/general/upload-image-to-private-supabase.js +2 -2
  91. package/general/upload-image-to-public-supabase.js +2 -2
  92. package/general/validate-email.js +1 -1
  93. package/hooks/use-fetch.js +11 -12
  94. package/hooks/use-module-entity.js +5 -6
  95. package/hooks/use-sticky.js +0 -1
  96. package/hooks/with-seo.d.ts +1 -1
  97. package/hooks/with-seo.js +3 -4
  98. package/local-storage/get-storage-value.js +0 -1
  99. package/package.json +22 -13
  100. package/setupTests.js +1 -2
  101. package/storybook/generate-sitemap.js +0 -1
  102. package/storybook/preview.js +1 -4
  103. package/storybook/react-design-story-script.js +0 -2
  104. package/storybook/react-emoji-collection.js +8 -6
  105. package/storybook/react-emoji-story-script.js +0 -2
  106. package/storybook/react-icon-collection.js +4 -3
  107. package/storybook/react-icon-story-script.js +0 -2
  108. package/storybook/react-logo-collection.js +4 -3
  109. package/storybook/react-logo-story-script.js +0 -2
  110. package/storybook/responsive-component.js +14 -7
@@ -1,29 +1,78 @@
1
1
  import { BranchBE } from '../type';
2
- interface GetBranchesArgs {
3
- prisma: any;
2
+ type PrismaClient = any;
3
+ interface ListBranchArgs {
4
+ currentPage: number;
5
+ include?: {
6
+ [key: string]: any;
7
+ };
8
+ orderBy?: {
9
+ [key: string]: any;
10
+ };
11
+ pageLimit: number;
12
+ prisma: PrismaClient;
13
+ queryWhere?: {
14
+ [key: string]: any;
15
+ };
4
16
  }
5
- interface GetBranchByIdArgs {
6
- id: string;
7
- prisma: any;
17
+ interface UnitBranchByIdArgs {
18
+ include?: {
19
+ [key: string]: any;
20
+ };
21
+ prisma: PrismaClient;
22
+ queryWhere: {
23
+ [key: string]: any;
24
+ };
8
25
  }
9
- interface PostBranchArgs {
26
+ interface UpdateBranchArgs {
10
27
  branchAddress: string;
11
28
  branchName: string;
12
29
  enabled: boolean;
13
- id: string;
14
- isDefault: boolean;
30
+ id?: string;
31
+ include?: {
32
+ [key: string]: any;
33
+ };
34
+ isDefault?: boolean;
15
35
  personEmail: string;
16
36
  personName: string;
17
37
  personPhone: string;
18
38
  preferenceId: string;
19
- prisma: any;
39
+ prisma: PrismaClient;
40
+ queryWhere?: {
41
+ [key: string]: any;
42
+ };
20
43
  }
21
44
  interface DeleteBranchArgs {
22
- id: string;
23
- prisma: any;
45
+ include?: {
46
+ [key: string]: any;
47
+ };
48
+ prisma: PrismaClient;
49
+ queryWhere: {
50
+ [key: string]: any;
51
+ };
24
52
  }
25
- export declare const getBranches: ({ prisma, }: GetBranchesArgs) => Promise<Array<BranchBE>>;
26
- export declare const getBranchById: ({ prisma, id }: GetBranchByIdArgs) => Promise<BranchBE>;
27
- export declare const postBranch: ({ prisma, branchAddress, branchName, enabled, id, isDefault, personEmail, personName, personPhone, preferenceId, }: PostBranchArgs) => Promise<Array<BranchBE>>;
28
- export declare const deleteBranch: ({ prisma, id, }: DeleteBranchArgs) => Promise<BranchBE>;
53
+ /**
54
+ * Retrieves all branches from the database with pagination
55
+ * @param {ListBranchArgs} args - Object containing prisma client, pagination, and filter options
56
+ * @returns {Promise<[number, Array<BranchBE>]>} Tuple of [total count, array of branches]
57
+ */
58
+ export declare const listBranch: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: ListBranchArgs) => Promise<[number, Array<BranchBE>]>;
59
+ /**
60
+ * Retrieves a single branch by ID
61
+ * @param {UnitBranchByIdArgs} args - Object containing prisma client and branch id
62
+ * @returns {Promise<BranchBE | null>} Branch if found, null otherwise
63
+ */
64
+ export declare const unitBranchById: ({ include, prisma, queryWhere, }: UnitBranchByIdArgs) => Promise<BranchBE | null>;
65
+ /**
66
+ * Creates a new branch or updates an existing one
67
+ * @param {UpdateBranchArgs} args - Object containing prisma client and branch data
68
+ * @returns {Promise<BranchBE>} Created or updated branch
69
+ */
70
+ export declare const updateBranch: ({ branchAddress, branchName, enabled, id, include, isDefault, personEmail, personName, personPhone, preferenceId, prisma, queryWhere, }: UpdateBranchArgs) => Promise<BranchBE>;
71
+ /**
72
+ * Deletes a branch by ID
73
+ * @param {DeleteBranchArgs} args - Object containing prisma client and branch id
74
+ * @returns {Promise<BranchBE>} Deleted branch
75
+ * @throws {Error} If branch ID is not provided or branch not found
76
+ */
77
+ export declare const deleteBranch: ({ include, prisma, queryWhere, }: DeleteBranchArgs) => Promise<BranchBE>;
29
78
  export {};
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
3
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,90 +47,134 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
47
  }
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.deleteBranch = exports.postBranch = exports.getBranchById = exports.getBranches = void 0;
41
- var getBranches = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
50
+ exports.deleteBranch = exports.updateBranch = exports.unitBranchById = exports.listBranch = void 0;
51
+ /**
52
+ * Retrieves all branches from the database with pagination
53
+ * @param {ListBranchArgs} args - Object containing prisma client, pagination, and filter options
54
+ * @returns {Promise<[number, Array<BranchBE>]>} Tuple of [total count, array of branches]
55
+ */
56
+ var listBranch = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
57
  var branches;
43
- var prisma = _b.prisma;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0: return [4 /*yield*/, prisma.branch.findMany({
47
- orderBy: {
48
- createdAt: 'desc',
49
- },
50
- })];
58
+ var currentPage = _b.currentPage, _c = _b.include, include = _c === void 0 ? {} : _c, _d = _b.orderBy, orderBy = _d === void 0 ? { createdAt: 'desc' } : _d, pageLimit = _b.pageLimit, prisma = _b.prisma, _e = _b.queryWhere, queryWhere = _e === void 0 ? {} : _e;
59
+ return __generator(this, function (_f) {
60
+ switch (_f.label) {
61
+ case 0:
62
+ if (!currentPage || currentPage < 1) {
63
+ throw new Error('Valid current page is required');
64
+ }
65
+ if (!pageLimit || pageLimit < 1) {
66
+ throw new Error('Valid page limit is required');
67
+ }
68
+ return [4 /*yield*/, prisma.$transaction([
69
+ prisma.branch.count({
70
+ where: queryWhere,
71
+ }),
72
+ prisma.branch.findMany({
73
+ include: include,
74
+ orderBy: orderBy,
75
+ skip: (currentPage - 1) * pageLimit,
76
+ take: pageLimit,
77
+ where: queryWhere,
78
+ }),
79
+ ])];
51
80
  case 1:
52
- branches = _c.sent();
81
+ branches = _f.sent();
53
82
  return [2 /*return*/, branches];
54
83
  }
55
84
  });
56
85
  }); };
57
- exports.getBranches = getBranches;
58
- var getBranchById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
86
+ exports.listBranch = listBranch;
87
+ /**
88
+ * Retrieves a single branch by ID
89
+ * @param {UnitBranchByIdArgs} args - Object containing prisma client and branch id
90
+ * @returns {Promise<BranchBE | null>} Branch if found, null otherwise
91
+ */
92
+ var unitBranchById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
59
93
  var branch;
60
- var prisma = _b.prisma, id = _b.id;
61
- return __generator(this, function (_c) {
62
- switch (_c.label) {
63
- case 0: return [4 /*yield*/, prisma.branch.findUnique({
64
- where: {
65
- id: id,
66
- },
67
- })];
94
+ var _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, queryWhere = _b.queryWhere;
95
+ return __generator(this, function (_d) {
96
+ switch (_d.label) {
97
+ case 0:
98
+ if (!(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
99
+ throw new Error('Branch ID is required');
100
+ }
101
+ return [4 /*yield*/, prisma.branch.findUnique({
102
+ include: include,
103
+ where: queryWhere,
104
+ })];
68
105
  case 1:
69
- branch = _c.sent();
106
+ branch = _d.sent();
70
107
  return [2 /*return*/, branch];
71
108
  }
72
109
  });
73
110
  }); };
74
- exports.getBranchById = getBranchById;
75
- var postBranch = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
76
- var branch;
77
- var prisma = _b.prisma, branchAddress = _b.branchAddress, branchName = _b.branchName, enabled = _b.enabled, id = _b.id, isDefault = _b.isDefault, personEmail = _b.personEmail, personName = _b.personName, personPhone = _b.personPhone, preferenceId = _b.preferenceId;
78
- return __generator(this, function (_c) {
79
- switch (_c.label) {
80
- case 0: return [4 /*yield*/, prisma.branch.upsert({
81
- where: {
82
- id: id,
83
- },
84
- update: {
85
- branchAddress: branchAddress,
86
- branchName: branchName,
87
- enabled: enabled,
88
- isDefault: isDefault,
89
- personEmail: personEmail,
90
- personName: personName,
91
- personPhone: personPhone,
92
- preferenceId: preferenceId,
93
- },
94
- create: {
95
- branchAddress: branchAddress,
96
- branchName: branchName,
97
- enabled: enabled,
98
- isDefault: isDefault,
99
- personEmail: personEmail,
100
- personName: personName,
101
- personPhone: personPhone,
102
- preferenceId: preferenceId,
103
- },
104
- })];
111
+ exports.unitBranchById = unitBranchById;
112
+ /**
113
+ * Creates a new branch or updates an existing one
114
+ * @param {UpdateBranchArgs} args - Object containing prisma client and branch data
115
+ * @returns {Promise<BranchBE>} Created or updated branch
116
+ */
117
+ var updateBranch = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
118
+ var branchData, branch;
119
+ var branchAddress = _b.branchAddress, branchName = _b.branchName, enabled = _b.enabled, id = _b.id, include = _b.include, _c = _b.isDefault, isDefault = _c === void 0 ? false : _c, personEmail = _b.personEmail, personName = _b.personName, personPhone = _b.personPhone, preferenceId = _b.preferenceId, prisma = _b.prisma, queryWhere = _b.queryWhere;
120
+ return __generator(this, function (_d) {
121
+ switch (_d.label) {
122
+ case 0:
123
+ if (!branchAddress ||
124
+ !branchName ||
125
+ !personEmail ||
126
+ !personName ||
127
+ !personPhone ||
128
+ !preferenceId) {
129
+ throw new Error('Branch address, branch name, person email, person name, person phone, and preference ID are required');
130
+ }
131
+ if (!id || !(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
132
+ throw new Error('Branch ID is required');
133
+ }
134
+ branchData = {
135
+ branchAddress: branchAddress,
136
+ branchName: branchName,
137
+ enabled: enabled,
138
+ isDefault: isDefault,
139
+ personEmail: personEmail,
140
+ personName: personName,
141
+ personPhone: personPhone,
142
+ preferenceId: preferenceId,
143
+ };
144
+ return [4 /*yield*/, prisma.branch.upsert({
145
+ where: queryWhere,
146
+ update: branchData,
147
+ create: __assign({ id: id }, branchData),
148
+ include: include,
149
+ })];
105
150
  case 1:
106
- branch = _c.sent();
151
+ branch = _d.sent();
107
152
  return [2 /*return*/, branch];
108
153
  }
109
154
  });
110
155
  }); };
111
- exports.postBranch = postBranch;
156
+ exports.updateBranch = updateBranch;
157
+ /**
158
+ * Deletes a branch by ID
159
+ * @param {DeleteBranchArgs} args - Object containing prisma client and branch id
160
+ * @returns {Promise<BranchBE>} Deleted branch
161
+ * @throws {Error} If branch ID is not provided or branch not found
162
+ */
112
163
  var deleteBranch = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
113
164
  var branch;
114
- var prisma = _b.prisma, id = _b.id;
115
- return __generator(this, function (_c) {
116
- switch (_c.label) {
117
- case 0: return [4 /*yield*/, prisma.branch.delete({
118
- where: {
119
- id: id,
120
- },
121
- })];
165
+ var _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, queryWhere = _b.queryWhere;
166
+ return __generator(this, function (_d) {
167
+ switch (_d.label) {
168
+ case 0:
169
+ if (!(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
170
+ throw new Error('Branch ID is required');
171
+ }
172
+ return [4 /*yield*/, prisma.branch.delete({
173
+ include: include,
174
+ where: queryWhere,
175
+ })];
122
176
  case 1:
123
- branch = _c.sent();
177
+ branch = _d.sent();
124
178
  return [2 /*return*/, branch];
125
179
  }
126
180
  });
@@ -1,41 +1,75 @@
1
1
  import { CompanyBE } from '../type';
2
- interface GetCompaniesArgs {
3
- prisma: any;
4
- }
5
- interface GetCompanyByIdArgs {
6
- id: string;
7
- prisma: any;
8
- }
9
- interface PostCompaniesArgs {
2
+ type PrismaClient = any;
3
+ interface ListCompanyArgs {
10
4
  currentPage: number;
11
- include: {
5
+ include?: {
12
6
  [key: string]: any;
13
7
  };
14
- orderBy: {
8
+ orderBy?: {
15
9
  [key: string]: any;
16
10
  };
17
11
  pageLimit: number;
18
- prisma: any;
12
+ prisma: PrismaClient;
13
+ queryWhere?: {
14
+ [key: string]: any;
15
+ };
16
+ }
17
+ interface UnitCompanyByIdArgs {
18
+ include?: {
19
+ [key: string]: any;
20
+ };
21
+ prisma: PrismaClient;
19
22
  queryWhere: {
20
23
  [key: string]: any;
21
24
  };
22
25
  }
23
- interface PostCompanyArgs {
24
- prisma: any;
26
+ interface UpdateCompanyArgs {
25
27
  country: string;
26
28
  email: string;
27
- name: boolean;
28
- id: string;
29
- phone: boolean;
30
- website: string;
29
+ id?: string;
30
+ include?: {
31
+ [key: string]: any;
32
+ };
33
+ name: string;
34
+ phone: string;
35
+ prisma: PrismaClient;
36
+ queryWhere?: {
37
+ [key: string]: any;
38
+ };
39
+ website?: string;
31
40
  }
32
41
  interface DeleteCompanyArgs {
33
- id: string;
34
- prisma: any;
42
+ include?: {
43
+ [key: string]: any;
44
+ };
45
+ prisma: PrismaClient;
46
+ queryWhere: {
47
+ [key: string]: any;
48
+ };
35
49
  }
36
- export declare const getCompanies: ({ prisma, }: GetCompaniesArgs) => Promise<Array<CompanyBE>>;
37
- export declare const getCompanyById: ({ prisma, id, }: GetCompanyByIdArgs) => Promise<CompanyBE>;
38
- export declare const postCompanies: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: PostCompaniesArgs) => Promise<Array<CompanyBE>>;
39
- export declare const postCompany: ({ prisma, country, email, name, id, phone, website, }: PostCompanyArgs) => Promise<Array<CompanyBE>>;
40
- export declare const deleteCompany: ({ prisma, id, }: DeleteCompanyArgs) => Promise<CompanyBE>;
50
+ /**
51
+ * Retrieves all companies from the database with pagination
52
+ * @param {ListCompanyArgs} args - Object containing prisma client, pagination, and filter options
53
+ * @returns {Promise<[number, Array<CompanyBE>]>} Tuple of [total count, array of companies]
54
+ */
55
+ export declare const listCompany: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: ListCompanyArgs) => Promise<[number, Array<CompanyBE>]>;
56
+ /**
57
+ * Retrieves a single company by ID
58
+ * @param {UnitCompanyByIdArgs} args - Object containing prisma client and company id
59
+ * @returns {Promise<CompanyBE | null>} Company if found, null otherwise
60
+ */
61
+ export declare const unitCompanyById: ({ include, prisma, queryWhere, }: UnitCompanyByIdArgs) => Promise<CompanyBE | null>;
62
+ /**
63
+ * Creates a new company or updates an existing one
64
+ * @param {UpdateCompanyArgs} args - Object containing prisma client and company data
65
+ * @returns {Promise<CompanyBE>} Created or updated company
66
+ */
67
+ export declare const updateCompany: ({ country, email, id, include, name, phone, prisma, queryWhere, website, }: UpdateCompanyArgs) => Promise<CompanyBE>;
68
+ /**
69
+ * Deletes a company by ID
70
+ * @param {DeleteCompanyArgs} args - Object containing prisma client and company id
71
+ * @returns {Promise<CompanyBE>} Deleted company
72
+ * @throws {Error} If company ID is not provided or company not found
73
+ */
74
+ export declare const deleteCompany: ({ include, prisma, queryWhere, }: DeleteCompanyArgs) => Promise<CompanyBE>;
41
75
  export {};
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any, no-restricted-globals, @typescript-eslint/array-type */
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
3
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,108 +47,126 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
47
  }
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.deleteCompany = exports.postCompany = exports.postCompanies = exports.getCompanyById = exports.getCompanies = void 0;
41
- var getCompanies = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
50
+ exports.deleteCompany = exports.updateCompany = exports.unitCompanyById = exports.listCompany = void 0;
51
+ /**
52
+ * Retrieves all companies from the database with pagination
53
+ * @param {ListCompanyArgs} args - Object containing prisma client, pagination, and filter options
54
+ * @returns {Promise<[number, Array<CompanyBE>]>} Tuple of [total count, array of companies]
55
+ */
56
+ var listCompany = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
57
  var companies;
43
- var prisma = _b.prisma;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0: return [4 /*yield*/, prisma.company.findMany({
47
- orderBy: {
48
- createdAt: 'desc',
49
- },
50
- })];
58
+ var currentPage = _b.currentPage, _c = _b.include, include = _c === void 0 ? {} : _c, _d = _b.orderBy, orderBy = _d === void 0 ? { createdAt: 'desc' } : _d, pageLimit = _b.pageLimit, prisma = _b.prisma, _e = _b.queryWhere, queryWhere = _e === void 0 ? {} : _e;
59
+ return __generator(this, function (_f) {
60
+ switch (_f.label) {
61
+ case 0:
62
+ if (!currentPage || currentPage < 1) {
63
+ throw new Error('Valid current page is required');
64
+ }
65
+ if (!pageLimit || pageLimit < 1) {
66
+ throw new Error('Valid page limit is required');
67
+ }
68
+ return [4 /*yield*/, prisma.$transaction([
69
+ prisma.company.count({
70
+ where: queryWhere,
71
+ }),
72
+ prisma.company.findMany({
73
+ include: include,
74
+ orderBy: orderBy,
75
+ skip: (currentPage - 1) * pageLimit,
76
+ take: pageLimit,
77
+ where: queryWhere,
78
+ }),
79
+ ])];
51
80
  case 1:
52
- companies = _c.sent();
81
+ companies = _f.sent();
53
82
  return [2 /*return*/, companies];
54
83
  }
55
84
  });
56
85
  }); };
57
- exports.getCompanies = getCompanies;
58
- var getCompanyById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
86
+ exports.listCompany = listCompany;
87
+ /**
88
+ * Retrieves a single company by ID
89
+ * @param {UnitCompanyByIdArgs} args - Object containing prisma client and company id
90
+ * @returns {Promise<CompanyBE | null>} Company if found, null otherwise
91
+ */
92
+ var unitCompanyById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
59
93
  var company;
60
- var prisma = _b.prisma, id = _b.id;
61
- return __generator(this, function (_c) {
62
- switch (_c.label) {
63
- case 0: return [4 /*yield*/, prisma.company.findUnique({
64
- where: {
65
- id: id,
66
- },
67
- })];
94
+ var _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, queryWhere = _b.queryWhere;
95
+ return __generator(this, function (_d) {
96
+ switch (_d.label) {
97
+ case 0:
98
+ if (!(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
99
+ throw new Error('Company ID is required');
100
+ }
101
+ return [4 /*yield*/, prisma.company.findUnique({
102
+ include: include,
103
+ where: queryWhere,
104
+ })];
68
105
  case 1:
69
- company = _c.sent();
106
+ company = _d.sent();
70
107
  return [2 /*return*/, company];
71
108
  }
72
109
  });
73
110
  }); };
74
- exports.getCompanyById = getCompanyById;
75
- var postCompanies = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
76
- var companies;
77
- var currentPage = _b.currentPage, include = _b.include, orderBy = _b.orderBy, pageLimit = _b.pageLimit, prisma = _b.prisma, queryWhere = _b.queryWhere;
111
+ exports.unitCompanyById = unitCompanyById;
112
+ /**
113
+ * Creates a new company or updates an existing one
114
+ * @param {UpdateCompanyArgs} args - Object containing prisma client and company data
115
+ * @returns {Promise<CompanyBE>} Created or updated company
116
+ */
117
+ var updateCompany = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
118
+ var companyData, company;
119
+ var country = _b.country, email = _b.email, id = _b.id, include = _b.include, name = _b.name, phone = _b.phone, prisma = _b.prisma, queryWhere = _b.queryWhere, website = _b.website;
78
120
  return __generator(this, function (_c) {
79
121
  switch (_c.label) {
80
- case 0: return [4 /*yield*/, prisma.$transaction([
81
- prisma.company.count({
122
+ case 0:
123
+ if (!country || !email || !name || !phone) {
124
+ throw new Error('Country, email, name, and phone are required');
125
+ }
126
+ if (!id || !(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
127
+ throw new Error('Company ID is required');
128
+ }
129
+ companyData = {
130
+ country: country,
131
+ email: email,
132
+ name: name,
133
+ phone: phone,
134
+ website: website || null,
135
+ };
136
+ return [4 /*yield*/, prisma.company.upsert({
82
137
  where: queryWhere,
83
- }),
84
- prisma.company.findMany({
85
- orderBy: orderBy,
138
+ update: companyData,
139
+ create: __assign({ id: id }, companyData),
86
140
  include: include,
87
- where: queryWhere,
88
- take: pageLimit,
89
- skip: (currentPage - 1) * pageLimit,
90
- }),
91
- ])];
92
- case 1:
93
- companies = _c.sent();
94
- return [2 /*return*/, companies];
95
- }
96
- });
97
- }); };
98
- exports.postCompanies = postCompanies;
99
- var postCompany = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
100
- var company;
101
- var prisma = _b.prisma, country = _b.country, email = _b.email, name = _b.name, id = _b.id, phone = _b.phone, website = _b.website;
102
- return __generator(this, function (_c) {
103
- switch (_c.label) {
104
- case 0: return [4 /*yield*/, prisma.company.upsert({
105
- where: {
106
- id: id,
107
- },
108
- update: {
109
- country: country,
110
- email: email,
111
- name: name,
112
- phone: phone,
113
- website: website,
114
- },
115
- create: {
116
- country: country,
117
- email: email,
118
- name: name,
119
- phone: phone,
120
- website: website,
121
- },
122
- })];
141
+ })];
123
142
  case 1:
124
143
  company = _c.sent();
125
144
  return [2 /*return*/, company];
126
145
  }
127
146
  });
128
147
  }); };
129
- exports.postCompany = postCompany;
148
+ exports.updateCompany = updateCompany;
149
+ /**
150
+ * Deletes a company by ID
151
+ * @param {DeleteCompanyArgs} args - Object containing prisma client and company id
152
+ * @returns {Promise<CompanyBE>} Deleted company
153
+ * @throws {Error} If company ID is not provided or company not found
154
+ */
130
155
  var deleteCompany = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
131
156
  var company;
132
- var prisma = _b.prisma, id = _b.id;
133
- return __generator(this, function (_c) {
134
- switch (_c.label) {
135
- case 0: return [4 /*yield*/, prisma.company.delete({
136
- where: {
137
- id: id,
138
- },
139
- })];
157
+ var _c = _b.include, include = _c === void 0 ? {} : _c, prisma = _b.prisma, queryWhere = _b.queryWhere;
158
+ return __generator(this, function (_d) {
159
+ switch (_d.label) {
160
+ case 0:
161
+ if (!(queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id)) {
162
+ throw new Error('Company ID is required');
163
+ }
164
+ return [4 /*yield*/, prisma.company.delete({
165
+ include: include,
166
+ where: queryWhere,
167
+ })];
140
168
  case 1:
141
- company = _c.sent();
169
+ company = _d.sent();
142
170
  return [2 /*return*/, company];
143
171
  }
144
172
  });
@@ -1,15 +1,22 @@
1
1
  import { CompanyBE } from '../type';
2
+ type PrismaClient = any;
2
3
  interface PostCompaniesReportArgs {
3
- prisma: any;
4
- queryWhere: {
4
+ prisma: PrismaClient;
5
+ queryWhere?: {
5
6
  [key: string]: any;
6
7
  };
7
- include: {
8
+ include?: {
8
9
  [key: string]: any;
9
10
  };
10
- orderBy: {
11
+ orderBy?: {
11
12
  [key: string]: any;
12
13
  };
13
14
  }
14
- export declare const postCompaniesReport: ({ prisma, queryWhere, orderBy, include, }: PostCompaniesReportArgs) => Promise<Array<CompanyBE>>;
15
+ /**
16
+ * Retrieves companies report data with count and full list
17
+ * This is typically used for generating reports without pagination
18
+ * @param {PostCompaniesReportArgs} args - Object containing prisma client and query options
19
+ * @returns {Promise<[number, Array<CompanyBE>]>} Tuple containing total count and array of all matching companies
20
+ */
21
+ export declare const postCompaniesReport: ({ prisma, queryWhere, orderBy, include, }: PostCompaniesReportArgs) => Promise<[number, Array<CompanyBE>]>;
15
22
  export {};