@react-pakistan/util-functions 1.24.65 → 1.24.66

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 +46 -31
  32. package/api/stellar-solutions/product/index.js +142 -113
  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,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,114 +47,140 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
47
  }
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.deleteProductCategory = exports.postProductCategory = exports.postProductCategories = exports.getProductCategoryById = exports.getProductCategories = void 0;
41
- var getProductCategories = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var productCategories;
43
- var prisma = _b.prisma;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0: return [4 /*yield*/, prisma.productCategory.findMany({
47
- orderBy: {
48
- createdAt: 'desc',
49
- },
50
- include: {
51
- products: true,
52
- },
53
- })];
54
- case 1:
55
- productCategories = _c.sent();
56
- return [2 /*return*/, productCategories];
57
- }
58
- });
59
- }); };
60
- exports.getProductCategories = getProductCategories;
61
- var getProductCategoryById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
62
- var productCategory;
63
- var prisma = _b.prisma, id = _b.id;
64
- return __generator(this, function (_c) {
65
- switch (_c.label) {
66
- case 0: return [4 /*yield*/, prisma.productCategory.findUnique({
67
- where: {
68
- id: id,
69
- },
70
- include: {
71
- products: true,
72
- },
73
- })];
74
- case 1:
75
- productCategory = _c.sent();
76
- return [2 /*return*/, productCategory];
77
- }
78
- });
79
- }); };
80
- exports.getProductCategoryById = getProductCategoryById;
81
- var postProductCategories = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
82
- var productCategories, err_1;
83
- var currentPage = _b.currentPage, include = _b.include, orderBy = _b.orderBy, pageLimit = _b.pageLimit, prisma = _b.prisma, queryWhere = _b.queryWhere;
84
- return __generator(this, function (_c) {
85
- switch (_c.label) {
50
+ exports.deleteProductCategory = exports.updateProductCategory = exports.unitProductCategoryById = exports.listProductCategory = void 0;
51
+ /**
52
+ * Retrieves a paginated list of product categories
53
+ * @param {ListProductCategoryArgs} args - Object containing prisma client, pagination, filtering, and ordering options
54
+ * @returns {Promise<[number, Array<ProductCategoryBE>]>} Tuple containing total count and array of product categories
55
+ */
56
+ var listProductCategory = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
+ var skip, _c, count, data;
58
+ var _d = _b.currentPage, currentPage = _d === void 0 ? 1 : _d, _e = _b.include, include = _e === void 0 ? {
59
+ products: true,
60
+ } : _e, _f = _b.orderBy, orderBy = _f === void 0 ? { createdAt: 'desc' } : _f, _g = _b.pageLimit, pageLimit = _g === void 0 ? 10 : _g, prisma = _b.prisma, _h = _b.queryWhere, queryWhere = _h === void 0 ? {} : _h;
61
+ return __generator(this, function (_j) {
62
+ switch (_j.label) {
86
63
  case 0:
87
- _c.trys.push([0, 2, , 3]);
88
- return [4 /*yield*/, prisma.$transaction([
64
+ if (currentPage < 1) {
65
+ throw new Error('Current page must be greater than or equal to 1');
66
+ }
67
+ if (pageLimit < 1) {
68
+ throw new Error('Page limit must be greater than or equal to 1');
69
+ }
70
+ skip = (currentPage - 1) * pageLimit;
71
+ return [4 /*yield*/, Promise.all([
89
72
  prisma.productCategory.count({
90
73
  where: queryWhere,
91
74
  }),
92
75
  prisma.productCategory.findMany({
76
+ include: include || null,
93
77
  orderBy: orderBy,
94
- include: include,
95
- where: queryWhere,
78
+ skip: skip,
96
79
  take: pageLimit,
97
- skip: (currentPage - 1) * pageLimit,
80
+ where: queryWhere,
98
81
  }),
99
82
  ])];
100
83
  case 1:
101
- productCategories = _c.sent();
102
- return [3 /*break*/, 3];
103
- case 2:
104
- err_1 = _c.sent();
105
- return [2 /*return*/, err_1];
106
- case 3: return [2 /*return*/, productCategories];
84
+ _c = _j.sent(), count = _c[0], data = _c[1];
85
+ return [2 /*return*/, [count, data]];
107
86
  }
108
87
  });
109
88
  }); };
110
- exports.postProductCategories = postProductCategories;
111
- var postProductCategory = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
89
+ exports.listProductCategory = listProductCategory;
90
+ /**
91
+ * Retrieves a single product category by its ID
92
+ * @param {UnitProductCategoryByIdArgs} args - Object containing prisma client, product category ID, and optional query parameters
93
+ * @returns {Promise<ProductCategoryBE | null>} Product category or null if not found
94
+ */
95
+ var unitProductCategoryById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
112
96
  var productCategory;
113
- var description = _b.description, id = _b.id, name = _b.name, prisma = _b.prisma;
114
- return __generator(this, function (_c) {
115
- switch (_c.label) {
116
- case 0: return [4 /*yield*/, prisma.productCategory.upsert({
117
- where: {
118
- id: id,
119
- },
120
- update: {
121
- description: description,
122
- name: name,
123
- },
124
- create: {
125
- description: description,
126
- name: name,
127
- },
128
- })];
97
+ var id = _b.id, _c = _b.include, include = _c === void 0 ? {
98
+ products: true,
99
+ } : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
100
+ return __generator(this, function (_e) {
101
+ switch (_e.label) {
102
+ case 0:
103
+ if (!id) {
104
+ throw new Error('Product category ID is required');
105
+ }
106
+ if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
107
+ throw new Error('ID mismatch between parameter and queryWhere');
108
+ }
109
+ return [4 /*yield*/, prisma.productCategory.findUnique({
110
+ include: include || null,
111
+ where: __assign({ id: id }, queryWhere),
112
+ })];
129
113
  case 1:
130
- productCategory = _c.sent();
114
+ productCategory = _e.sent();
131
115
  return [2 /*return*/, productCategory];
132
116
  }
133
117
  });
134
118
  }); };
135
- exports.postProductCategory = postProductCategory;
119
+ exports.unitProductCategoryById = unitProductCategoryById;
120
+ /**
121
+ * Creates or updates a product category
122
+ * @param {UpdateProductCategoryArgs} args - Object containing prisma client, product category data, and optional query parameters
123
+ * @returns {Promise<ProductCategoryBE>} Created or updated product category
124
+ */
125
+ var updateProductCategory = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
126
+ var productCategoryData, productCategory;
127
+ var description = _b.description, id = _b.id, _c = _b.include, include = _c === void 0 ? {
128
+ products: true,
129
+ } : _c, name = _b.name, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
130
+ return __generator(this, function (_e) {
131
+ switch (_e.label) {
132
+ case 0:
133
+ if (!id) {
134
+ throw new Error('Product category ID is required');
135
+ }
136
+ if (!name) {
137
+ throw new Error('Product category name is required');
138
+ }
139
+ if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
140
+ throw new Error('ID mismatch between parameter and queryWhere');
141
+ }
142
+ productCategoryData = {
143
+ description: description || null,
144
+ name: name,
145
+ };
146
+ return [4 /*yield*/, prisma.productCategory.upsert({
147
+ include: include || null,
148
+ where: __assign({ id: id }, queryWhere),
149
+ update: productCategoryData,
150
+ create: __assign({ id: id }, productCategoryData),
151
+ })];
152
+ case 1:
153
+ productCategory = _e.sent();
154
+ return [2 /*return*/, productCategory];
155
+ }
156
+ });
157
+ }); };
158
+ exports.updateProductCategory = updateProductCategory;
159
+ /**
160
+ * Deletes a product category by ID
161
+ * @param {DeleteProductCategoryArgs} args - Object containing prisma client, product category ID, and optional query parameters
162
+ * @returns {Promise<ProductCategoryBE>} Deleted product category
163
+ */
136
164
  var deleteProductCategory = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
137
165
  var productCategory;
138
- var prisma = _b.prisma, id = _b.id;
139
- return __generator(this, function (_c) {
140
- switch (_c.label) {
141
- case 0: return [4 /*yield*/, prisma.productCategory.delete({
142
- where: {
143
- id: id,
144
- },
145
- })];
166
+ var id = _b.id, _c = _b.include, include = _c === void 0 ? {
167
+ products: true,
168
+ } : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
169
+ return __generator(this, function (_e) {
170
+ switch (_e.label) {
171
+ case 0:
172
+ if (!id) {
173
+ throw new Error('Product category ID is required');
174
+ }
175
+ if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
176
+ throw new Error('ID mismatch between parameter and queryWhere');
177
+ }
178
+ return [4 /*yield*/, prisma.productCategory.delete({
179
+ include: include || null,
180
+ where: __assign({ id: id }, queryWhere),
181
+ })];
146
182
  case 1:
147
- productCategory = _c.sent();
183
+ productCategory = _e.sent();
148
184
  return [2 /*return*/, productCategory];
149
185
  }
150
186
  });
@@ -1,46 +1,77 @@
1
1
  import { ProfileBE } from '../type';
2
+ type PrismaClient = any;
2
3
  interface GetProfilesArgs {
3
- prisma: any;
4
+ prisma: PrismaClient;
4
5
  }
5
6
  interface GetProfileByIdArgs {
6
7
  id: string;
7
- prisma: any;
8
+ prisma: PrismaClient;
8
9
  }
9
10
  interface GetProfileByUserIdArgs {
10
- prisma: any;
11
+ prisma: PrismaClient;
11
12
  userId: string;
12
13
  }
13
14
  interface PostProfilesArgs {
14
15
  currentPage: number;
15
16
  pageLimit: number;
16
- prisma: any;
17
- queryWhere: {
17
+ prisma: PrismaClient;
18
+ queryWhere?: {
18
19
  [key: string]: any;
19
20
  };
20
21
  }
21
22
  interface PostProfileArgs {
22
- avatar: string;
23
- dob: string;
23
+ avatar?: string;
24
+ dob?: string;
24
25
  email: string;
25
26
  firstName: string;
26
27
  gender: string;
27
- id: string;
28
- language: string;
28
+ id?: string;
29
+ language?: string;
29
30
  lastName: string;
30
- location: string;
31
+ location?: string;
31
32
  phone: string;
32
- prisma: any;
33
- skill: string;
33
+ prisma: PrismaClient;
34
+ skill?: string;
34
35
  userId: string;
35
36
  }
36
37
  interface DeleteProfileArgs {
37
- prisma: any;
38
+ prisma: PrismaClient;
38
39
  id: string;
39
40
  }
41
+ /**
42
+ * Retrieves all profiles
43
+ * @param {GetProfilesArgs} args - Object containing prisma client
44
+ * @returns {Promise<Array<ProfileBE>>} Array of profiles ordered by creation date (newest first)
45
+ */
40
46
  export declare const getProfiles: ({ prisma, }: GetProfilesArgs) => Promise<Array<ProfileBE>>;
41
- export declare const getProfileById: ({ prisma, id, }: GetProfileByIdArgs) => Promise<ProfileBE>;
42
- export declare const getProfileByUserId: ({ prisma, userId, }: GetProfileByUserIdArgs) => Promise<ProfileBE>;
43
- export declare const postProfiles: ({ currentPage, pageLimit, prisma, queryWhere, }: PostProfilesArgs) => Promise<Array<ProfileBE>>;
44
- export declare const postProfile: ({ avatar, dob, email, firstName, gender, id, language, lastName, location, phone, prisma, skill, userId, }: PostProfileArgs) => Promise<Array<ProfileBE>>;
47
+ /**
48
+ * Retrieves a profile by its ID
49
+ * @param {GetProfileByIdArgs} args - Object containing prisma client and profile ID
50
+ * @returns {Promise<ProfileBE | null>} Profile or null if not found
51
+ */
52
+ export declare const getProfileById: ({ prisma, id, }: GetProfileByIdArgs) => Promise<ProfileBE | null>;
53
+ /**
54
+ * Retrieves a profile by user ID
55
+ * @param {GetProfileByUserIdArgs} args - Object containing prisma client and user ID
56
+ * @returns {Promise<ProfileBE | null>} Profile or null if not found
57
+ */
58
+ export declare const getProfileByUserId: ({ prisma, userId, }: GetProfileByUserIdArgs) => Promise<ProfileBE | null>;
59
+ /**
60
+ * Retrieves paginated profiles with filtering
61
+ * @param {PostProfilesArgs} args - Object containing prisma client, pagination, and filtering options
62
+ * @returns {Promise<[number, Array<ProfileBE>]>} Tuple of [total count, profiles array]
63
+ */
64
+ export declare const postProfiles: ({ currentPage, pageLimit, prisma, queryWhere, }: PostProfilesArgs) => Promise<[number, Array<ProfileBE>]>;
65
+ /**
66
+ * Creates a new profile or updates an existing one
67
+ * @param {PostProfileArgs} args - Object containing prisma client and profile data
68
+ * @returns {Promise<ProfileBE>} Created or updated profile
69
+ */
70
+ export declare const postProfile: ({ avatar, dob, email, firstName, gender, id, language, lastName, location, phone, prisma, skill, userId, }: PostProfileArgs) => Promise<ProfileBE>;
71
+ /**
72
+ * Deletes a profile by ID
73
+ * @param {DeleteProfileArgs} args - Object containing prisma client and profile ID
74
+ * @returns {Promise<ProfileBE>} Deleted profile
75
+ */
45
76
  export declare const deleteProfile: ({ prisma, id, }: DeleteProfileArgs) => Promise<ProfileBE>;
46
77
  export {};
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any, no-restricted-globals */
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) {
@@ -38,6 +48,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
50
  exports.deleteProfile = exports.postProfile = exports.postProfiles = exports.getProfileByUserId = exports.getProfileById = exports.getProfiles = void 0;
51
+ /**
52
+ * Retrieves all profiles
53
+ * @param {GetProfilesArgs} args - Object containing prisma client
54
+ * @returns {Promise<Array<ProfileBE>>} Array of profiles ordered by creation date (newest first)
55
+ */
41
56
  var getProfiles = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
57
  var profiles;
43
58
  var prisma = _b.prisma;
@@ -55,16 +70,25 @@ var getProfiles = function (_a) { return __awaiter(void 0, [_a], void 0, functio
55
70
  });
56
71
  }); };
57
72
  exports.getProfiles = getProfiles;
73
+ /**
74
+ * Retrieves a profile by its ID
75
+ * @param {GetProfileByIdArgs} args - Object containing prisma client and profile ID
76
+ * @returns {Promise<ProfileBE | null>} Profile or null if not found
77
+ */
58
78
  var getProfileById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
59
79
  var profile;
60
80
  var prisma = _b.prisma, id = _b.id;
61
81
  return __generator(this, function (_c) {
62
82
  switch (_c.label) {
63
- case 0: return [4 /*yield*/, prisma.profile.findUnique({
64
- where: {
65
- id: id,
66
- },
67
- })];
83
+ case 0:
84
+ if (!id) {
85
+ throw new Error('Profile ID is required');
86
+ }
87
+ return [4 /*yield*/, prisma.profile.findUnique({
88
+ where: {
89
+ id: id,
90
+ },
91
+ })];
68
92
  case 1:
69
93
  profile = _c.sent();
70
94
  return [2 /*return*/, profile];
@@ -72,16 +96,25 @@ var getProfileById = function (_a) { return __awaiter(void 0, [_a], void 0, func
72
96
  });
73
97
  }); };
74
98
  exports.getProfileById = getProfileById;
99
+ /**
100
+ * Retrieves a profile by user ID
101
+ * @param {GetProfileByUserIdArgs} args - Object containing prisma client and user ID
102
+ * @returns {Promise<ProfileBE | null>} Profile or null if not found
103
+ */
75
104
  var getProfileByUserId = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
76
105
  var profile;
77
106
  var prisma = _b.prisma, userId = _b.userId;
78
107
  return __generator(this, function (_c) {
79
108
  switch (_c.label) {
80
- case 0: return [4 /*yield*/, prisma.profile.findFirst({
81
- where: {
82
- userId: userId,
83
- },
84
- })];
109
+ case 0:
110
+ if (!userId) {
111
+ throw new Error('User ID is required');
112
+ }
113
+ return [4 /*yield*/, prisma.profile.findFirst({
114
+ where: {
115
+ userId: userId,
116
+ },
117
+ })];
85
118
  case 1:
86
119
  profile = _c.sent();
87
120
  return [2 /*return*/, profile];
@@ -89,84 +122,110 @@ var getProfileByUserId = function (_a) { return __awaiter(void 0, [_a], void 0,
89
122
  });
90
123
  }); };
91
124
  exports.getProfileByUserId = getProfileByUserId;
125
+ /**
126
+ * Retrieves paginated profiles with filtering
127
+ * @param {PostProfilesArgs} args - Object containing prisma client, pagination, and filtering options
128
+ * @returns {Promise<[number, Array<ProfileBE>]>} Tuple of [total count, profiles array]
129
+ */
92
130
  var postProfiles = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
93
131
  var profiles;
94
- var currentPage = _b.currentPage, pageLimit = _b.pageLimit, prisma = _b.prisma, queryWhere = _b.queryWhere;
95
- return __generator(this, function (_c) {
96
- switch (_c.label) {
97
- case 0: return [4 /*yield*/, prisma.$transaction([
98
- prisma.profile.count({
99
- where: queryWhere,
100
- }),
101
- prisma.profile.findMany({
102
- orderBy: {
103
- createdAt: 'desc',
104
- },
105
- where: queryWhere,
106
- take: pageLimit,
107
- skip: (currentPage - 1) * pageLimit,
108
- }),
109
- ])];
132
+ var _c = _b.currentPage, currentPage = _c === void 0 ? 1 : _c, _d = _b.pageLimit, pageLimit = _d === void 0 ? 10 : _d, prisma = _b.prisma, _e = _b.queryWhere, queryWhere = _e === void 0 ? {} : _e;
133
+ return __generator(this, function (_f) {
134
+ switch (_f.label) {
135
+ case 0:
136
+ if (currentPage < 1) {
137
+ throw new Error('Current page must be greater than 0');
138
+ }
139
+ if (pageLimit < 1) {
140
+ throw new Error('Page limit must be greater than 0');
141
+ }
142
+ return [4 /*yield*/, prisma.$transaction([
143
+ prisma.profile.count({
144
+ where: queryWhere,
145
+ }),
146
+ prisma.profile.findMany({
147
+ orderBy: {
148
+ createdAt: 'desc',
149
+ },
150
+ where: queryWhere,
151
+ take: pageLimit,
152
+ skip: (currentPage - 1) * pageLimit,
153
+ }),
154
+ ])];
110
155
  case 1:
111
- profiles = _c.sent();
156
+ profiles = _f.sent();
112
157
  return [2 /*return*/, profiles];
113
158
  }
114
159
  });
115
160
  }); };
116
161
  exports.postProfiles = postProfiles;
162
+ /**
163
+ * Creates a new profile or updates an existing one
164
+ * @param {PostProfileArgs} args - Object containing prisma client and profile data
165
+ * @returns {Promise<ProfileBE>} Created or updated profile
166
+ */
117
167
  var postProfile = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
118
- var profile;
168
+ var profileData, profile_1, profile;
119
169
  var avatar = _b.avatar, dob = _b.dob, email = _b.email, firstName = _b.firstName, gender = _b.gender, id = _b.id, language = _b.language, lastName = _b.lastName, location = _b.location, phone = _b.phone, prisma = _b.prisma, skill = _b.skill, userId = _b.userId;
120
170
  return __generator(this, function (_c) {
121
171
  switch (_c.label) {
122
- case 0: return [4 /*yield*/, prisma.profile.upsert({
123
- where: {
124
- id: id,
125
- },
126
- update: {
127
- avatar: avatar,
128
- dob: dob,
129
- email: email,
130
- firstName: firstName,
131
- gender: gender,
132
- language: language,
133
- lastName: lastName,
134
- location: location,
135
- phone: phone,
136
- skill: skill,
137
- userId: userId,
138
- },
139
- create: {
140
- avatar: avatar,
141
- dob: dob,
142
- email: email,
143
- firstName: firstName,
144
- gender: gender,
145
- language: language,
146
- lastName: lastName,
147
- location: location,
148
- phone: phone,
149
- skill: skill,
150
- userId: userId,
151
- },
152
- })];
172
+ case 0:
173
+ if (!email || !firstName || !gender || !lastName || !phone || !userId) {
174
+ throw new Error('Email, first name, gender, last name, phone, and user ID are required');
175
+ }
176
+ profileData = {
177
+ avatar: avatar || null,
178
+ dob: dob || null,
179
+ email: email,
180
+ firstName: firstName,
181
+ gender: gender,
182
+ language: language || null,
183
+ lastName: lastName,
184
+ location: location || null,
185
+ phone: phone,
186
+ skill: skill || null,
187
+ userId: userId,
188
+ };
189
+ if (!id) return [3 /*break*/, 2];
190
+ return [4 /*yield*/, prisma.profile.upsert({
191
+ where: {
192
+ id: id,
193
+ },
194
+ update: profileData,
195
+ create: __assign({ id: id }, profileData),
196
+ })];
153
197
  case 1:
198
+ profile_1 = _c.sent();
199
+ return [2 /*return*/, profile_1];
200
+ case 2: return [4 /*yield*/, prisma.profile.create({
201
+ data: profileData,
202
+ })];
203
+ case 3:
154
204
  profile = _c.sent();
155
205
  return [2 /*return*/, profile];
156
206
  }
157
207
  });
158
208
  }); };
159
209
  exports.postProfile = postProfile;
210
+ /**
211
+ * Deletes a profile by ID
212
+ * @param {DeleteProfileArgs} args - Object containing prisma client and profile ID
213
+ * @returns {Promise<ProfileBE>} Deleted profile
214
+ */
160
215
  var deleteProfile = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
161
216
  var profile;
162
217
  var prisma = _b.prisma, id = _b.id;
163
218
  return __generator(this, function (_c) {
164
219
  switch (_c.label) {
165
- case 0: return [4 /*yield*/, prisma.profile.delete({
166
- where: {
167
- id: id,
168
- },
169
- })];
220
+ case 0:
221
+ if (!id) {
222
+ throw new Error('Profile ID is required');
223
+ }
224
+ return [4 /*yield*/, prisma.profile.delete({
225
+ where: {
226
+ id: id,
227
+ },
228
+ })];
170
229
  case 1:
171
230
  profile = _c.sent();
172
231
  return [2 /*return*/, profile];