@react-pakistan/util-functions 1.24.64 → 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 +292 -177
  44. package/api/stellar-solutions/type.js +93 -1
  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) {
@@ -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.postPreference = exports.getPreferences = void 0;
51
+ /**
52
+ * Retrieves all preferences with related data
53
+ * @param {GetPreferencesArgs} args - Object containing prisma client
54
+ * @returns {Promise<Array<PreferenceBE>>} Array of preferences with related entities (banks, branches, currencies, etc.)
55
+ */
41
56
  var getPreferences = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
57
  var preferences;
43
58
  var prisma = _b.prisma;
@@ -48,7 +63,7 @@ var getPreferences = function (_a) { return __awaiter(void 0, [_a], void 0, func
48
63
  createdAt: 'desc',
49
64
  },
50
65
  include: {
51
- bankingDetails: true,
66
+ banks: true,
52
67
  branches: true,
53
68
  currencies: true,
54
69
  menuOrder: true,
@@ -63,23 +78,38 @@ var getPreferences = function (_a) { return __awaiter(void 0, [_a], void 0, func
63
78
  });
64
79
  }); };
65
80
  exports.getPreferences = getPreferences;
81
+ /**
82
+ * Creates a new preference or updates an existing one
83
+ * @param {PostPreferenceArgs} args - Object containing prisma client, optional preference ID, and onboarding status
84
+ * @returns {Promise<PreferenceBE>} Created or updated preference
85
+ */
66
86
  var postPreference = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
67
- var preference;
87
+ var preferenceData, preference_1, preference;
68
88
  var prisma = _b.prisma, id = _b.id, onboarding = _b.onboarding;
69
89
  return __generator(this, function (_c) {
70
90
  switch (_c.label) {
71
- case 0: return [4 /*yield*/, prisma.preference.upsert({
72
- where: {
73
- id: id,
74
- },
75
- update: {
76
- onboarding: onboarding,
77
- },
78
- create: {
79
- onboarding: onboarding,
80
- },
81
- })];
91
+ case 0:
92
+ if (typeof onboarding !== 'boolean') {
93
+ throw new Error('Onboarding status must be a boolean');
94
+ }
95
+ preferenceData = {
96
+ onboarding: onboarding,
97
+ };
98
+ if (!id) return [3 /*break*/, 2];
99
+ return [4 /*yield*/, prisma.preference.upsert({
100
+ where: {
101
+ id: id,
102
+ },
103
+ update: preferenceData,
104
+ create: __assign({ id: id }, preferenceData),
105
+ })];
82
106
  case 1:
107
+ preference_1 = _c.sent();
108
+ return [2 /*return*/, preference_1];
109
+ case 2: return [4 /*yield*/, prisma.preference.create({
110
+ data: preferenceData,
111
+ })];
112
+ case 3:
83
113
  preference = _c.sent();
84
114
  return [2 /*return*/, preference];
85
115
  }
@@ -1,47 +1,62 @@
1
1
  import { ProductBE } from '../type';
2
- interface GetProductsArgs {
3
- prisma: any;
2
+ type PrismaClient = any;
3
+ interface ListProductArgs {
4
+ currentPage?: number;
5
+ include?: any;
6
+ orderBy?: any;
7
+ pageLimit?: number;
8
+ prisma: PrismaClient;
9
+ queryWhere?: any;
4
10
  }
5
- interface GetProductByIdArgs {
11
+ interface UnitProductByIdArgs {
6
12
  id: string;
7
- prisma: any;
13
+ include?: any;
14
+ prisma: PrismaClient;
15
+ queryWhere?: any;
8
16
  }
9
- interface PostProductsArgs {
10
- currentPage: number;
11
- include: {
12
- [key: string]: any;
13
- };
14
- orderBy: {
15
- [key: string]: any;
16
- };
17
- pageLimit: number;
18
- prisma: any;
19
- queryWhere: {
20
- [key: string]: any;
21
- };
22
- }
23
- interface PostProductArgs {
24
- authorName: string;
17
+ interface UpdateProductArgs {
25
18
  buyPrice: string;
26
19
  currency: string;
27
- description: string;
20
+ description?: string;
28
21
  id: string;
29
- image: string;
30
- isbn: string;
22
+ image?: string;
31
23
  name: string;
32
- prisma: any;
24
+ include?: any;
25
+ prisma: PrismaClient;
33
26
  productCategoryId: string;
34
27
  quantity: string;
35
- ref: string;
28
+ queryWhere?: any;
29
+ ref?: string;
36
30
  salePrice: string;
37
31
  }
38
32
  interface DeleteProductArgs {
39
- prisma: any;
40
33
  id: string;
34
+ include?: any;
35
+ prisma: PrismaClient;
36
+ queryWhere?: any;
41
37
  }
42
- export declare const getProducts: ({ prisma, }: GetProductsArgs) => Promise<Array<ProductBE>>;
43
- export declare const getProductById: ({ prisma, id, }: GetProductByIdArgs) => Promise<ProductBE>;
44
- export declare const postProducts: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: PostProductsArgs) => Promise<Array<ProductBE>>;
45
- export declare const postProduct: ({ authorName, buyPrice, currency, description, id, image, isbn, name, prisma, productCategoryId, quantity, ref, salePrice, }: PostProductArgs) => Promise<Array<ProductBE> | Error>;
46
- export declare const deleteProduct: ({ prisma, id, }: DeleteProductArgs) => Promise<ProductBE>;
38
+ /**
39
+ * Retrieves a paginated list of products
40
+ * @param {ListProductArgs} args - Object containing prisma client, pagination, filtering, and ordering options
41
+ * @returns {Promise<[number, Array<ProductBE>]>} Tuple containing total count and array of products
42
+ */
43
+ export declare const listProduct: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: ListProductArgs) => Promise<[number, Array<ProductBE>]>;
44
+ /**
45
+ * Retrieves a single product by its ID
46
+ * @param {UnitProductByIdArgs} args - Object containing prisma client, product ID, and optional query parameters
47
+ * @returns {Promise<ProductBE | null>} Product or null if not found
48
+ */
49
+ export declare const unitProductById: ({ id, include, prisma, queryWhere, }: UnitProductByIdArgs) => Promise<ProductBE | null>;
50
+ /**
51
+ * Creates or updates a product
52
+ * @param {UpdateProductArgs} args - Object containing prisma client, product data, and optional query parameters
53
+ * @returns {Promise<ProductBE>} Created or updated product
54
+ */
55
+ export declare const updateProduct: ({ buyPrice, currency, description, id, image, include, name, prisma, productCategoryId, quantity, queryWhere, ref, salePrice, }: UpdateProductArgs) => Promise<ProductBE>;
56
+ /**
57
+ * Deletes a product by ID
58
+ * @param {DeleteProductArgs} args - Object containing prisma client, product ID, and optional query parameters
59
+ * @returns {Promise<ProductBE>} Deleted product
60
+ */
61
+ export declare const deleteProduct: ({ id, include, prisma, queryWhere, }: DeleteProductArgs) => Promise<ProductBE>;
47
62
  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) {
@@ -37,137 +47,156 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
47
  }
38
48
  };
39
49
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.deleteProduct = exports.postProduct = exports.postProducts = exports.getProductById = exports.getProducts = void 0;
41
- var getProducts = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var products;
43
- var prisma = _b.prisma;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0: return [4 /*yield*/, prisma.product.findMany({
47
- orderBy: {
48
- createdAt: 'desc',
49
- },
50
- include: {
51
- productCategory: true,
52
- quotesInvoices: true,
53
- },
54
- })];
50
+ exports.deleteProduct = exports.updateProduct = exports.unitProductById = exports.listProduct = void 0;
51
+ /**
52
+ * Retrieves a paginated list of products
53
+ * @param {ListProductArgs} args - Object containing prisma client, pagination, filtering, and ordering options
54
+ * @returns {Promise<[number, Array<ProductBE>]>} Tuple containing total count and array of products
55
+ */
56
+ var listProduct = 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
+ productCategory: true,
60
+ quotesInvoices: true,
61
+ } : _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;
62
+ return __generator(this, function (_j) {
63
+ switch (_j.label) {
64
+ case 0:
65
+ if (currentPage < 1) {
66
+ throw new Error('Current page must be greater than or equal to 1');
67
+ }
68
+ if (pageLimit < 1) {
69
+ throw new Error('Page limit must be greater than or equal to 1');
70
+ }
71
+ skip = (currentPage - 1) * pageLimit;
72
+ return [4 /*yield*/, Promise.all([
73
+ prisma.product.count({
74
+ where: queryWhere,
75
+ }),
76
+ prisma.product.findMany({
77
+ include: include || null,
78
+ orderBy: orderBy,
79
+ skip: skip,
80
+ take: pageLimit,
81
+ where: queryWhere,
82
+ }),
83
+ ])];
55
84
  case 1:
56
- products = _c.sent();
57
- return [2 /*return*/, products];
85
+ _c = _j.sent(), count = _c[0], data = _c[1];
86
+ return [2 /*return*/, [count, data]];
58
87
  }
59
88
  });
60
89
  }); };
61
- exports.getProducts = getProducts;
62
- var getProductById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
90
+ exports.listProduct = listProduct;
91
+ /**
92
+ * Retrieves a single product by its ID
93
+ * @param {UnitProductByIdArgs} args - Object containing prisma client, product ID, and optional query parameters
94
+ * @returns {Promise<ProductBE | null>} Product or null if not found
95
+ */
96
+ var unitProductById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
63
97
  var product;
64
- var prisma = _b.prisma, id = _b.id;
65
- return __generator(this, function (_c) {
66
- switch (_c.label) {
67
- case 0: return [4 /*yield*/, prisma.product.findUnique({
68
- where: {
69
- id: id,
70
- },
71
- include: {
72
- productCategory: true,
73
- quotesInvoices: true,
74
- },
75
- })];
98
+ var id = _b.id, _c = _b.include, include = _c === void 0 ? {
99
+ productCategory: true,
100
+ quotesInvoices: true,
101
+ } : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
102
+ return __generator(this, function (_e) {
103
+ switch (_e.label) {
104
+ case 0:
105
+ if (!id) {
106
+ throw new Error('Product ID is required');
107
+ }
108
+ if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
109
+ throw new Error('ID mismatch between parameter and queryWhere');
110
+ }
111
+ return [4 /*yield*/, prisma.product.findUnique({
112
+ include: include || null,
113
+ where: __assign({ id: id }, queryWhere),
114
+ })];
76
115
  case 1:
77
- product = _c.sent();
116
+ product = _e.sent();
78
117
  return [2 /*return*/, product];
79
118
  }
80
119
  });
81
120
  }); };
82
- exports.getProductById = getProductById;
83
- var postProducts = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
84
- var products;
85
- var currentPage = _b.currentPage, include = _b.include, orderBy = _b.orderBy, pageLimit = _b.pageLimit, prisma = _b.prisma, queryWhere = _b.queryWhere;
86
- return __generator(this, function (_c) {
87
- switch (_c.label) {
88
- case 0: return [4 /*yield*/, prisma.$transaction([
89
- prisma.product.count({
90
- where: queryWhere,
91
- }),
92
- prisma.product.findMany({
93
- include: include,
94
- orderBy: orderBy,
95
- skip: (currentPage - 1) * pageLimit,
96
- take: pageLimit,
97
- where: queryWhere,
98
- }),
99
- ])];
100
- case 1:
101
- products = _c.sent();
102
- return [2 /*return*/, products];
103
- }
104
- });
105
- }); };
106
- exports.postProducts = postProducts;
107
- var postProduct = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
108
- var product, error_1;
109
- var authorName = _b.authorName, buyPrice = _b.buyPrice, currency = _b.currency, description = _b.description, id = _b.id, image = _b.image, isbn = _b.isbn, name = _b.name, prisma = _b.prisma, productCategoryId = _b.productCategoryId, quantity = _b.quantity, ref = _b.ref, salePrice = _b.salePrice;
110
- return __generator(this, function (_c) {
111
- switch (_c.label) {
121
+ exports.unitProductById = unitProductById;
122
+ /**
123
+ * Creates or updates a product
124
+ * @param {UpdateProductArgs} args - Object containing prisma client, product data, and optional query parameters
125
+ * @returns {Promise<ProductBE>} Created or updated product
126
+ */
127
+ var updateProduct = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
128
+ var productData, product;
129
+ var buyPrice = _b.buyPrice, currency = _b.currency, description = _b.description, id = _b.id, image = _b.image, _c = _b.include, include = _c === void 0 ? {
130
+ productCategory: true,
131
+ quotesInvoices: true,
132
+ } : _c, name = _b.name, prisma = _b.prisma, productCategoryId = _b.productCategoryId, quantity = _b.quantity, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d, ref = _b.ref, salePrice = _b.salePrice;
133
+ return __generator(this, function (_e) {
134
+ switch (_e.label) {
112
135
  case 0:
113
- product = [];
114
- _c.label = 1;
115
- case 1:
116
- _c.trys.push([1, 3, , 4]);
136
+ if (!id) {
137
+ throw new Error('Product ID is required');
138
+ }
139
+ if (!buyPrice ||
140
+ !currency ||
141
+ !name ||
142
+ !productCategoryId ||
143
+ !quantity ||
144
+ !salePrice) {
145
+ throw new Error('Buy price, currency, name, product category ID, quantity, and sale price are required');
146
+ }
147
+ if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
148
+ throw new Error('ID mismatch between parameter and queryWhere');
149
+ }
150
+ productData = {
151
+ buyPrice: buyPrice,
152
+ currency: currency,
153
+ description: description || null,
154
+ image: image || null,
155
+ name: name,
156
+ productCategoryId: productCategoryId,
157
+ quantity: quantity,
158
+ ref: ref || null,
159
+ salePrice: salePrice,
160
+ };
117
161
  return [4 /*yield*/, prisma.product.upsert({
118
- where: {
119
- id: id,
120
- },
121
- update: {
122
- authorName: authorName,
123
- buyPrice: buyPrice,
124
- currency: currency,
125
- description: description,
126
- image: image,
127
- isbn: isbn,
128
- name: name,
129
- productCategoryId: productCategoryId,
130
- quantity: quantity,
131
- ref: ref,
132
- salePrice: salePrice,
133
- },
134
- create: {
135
- authorName: authorName,
136
- buyPrice: buyPrice,
137
- currency: currency,
138
- description: description,
139
- image: image,
140
- isbn: isbn,
141
- name: name,
142
- productCategoryId: productCategoryId,
143
- quantity: quantity,
144
- ref: ref,
145
- salePrice: salePrice,
146
- },
162
+ include: include || null,
163
+ where: __assign({ id: id }, queryWhere),
164
+ update: productData,
165
+ create: __assign({ id: id }, productData),
147
166
  })];
148
- case 2:
149
- product = _c.sent();
150
- return [3 /*break*/, 4];
151
- case 3:
152
- error_1 = _c.sent();
153
- return [2 /*return*/, error_1];
154
- case 4: return [2 /*return*/, product];
167
+ case 1:
168
+ product = _e.sent();
169
+ return [2 /*return*/, product];
155
170
  }
156
171
  });
157
172
  }); };
158
- exports.postProduct = postProduct;
173
+ exports.updateProduct = updateProduct;
174
+ /**
175
+ * Deletes a product by ID
176
+ * @param {DeleteProductArgs} args - Object containing prisma client, product ID, and optional query parameters
177
+ * @returns {Promise<ProductBE>} Deleted product
178
+ */
159
179
  var deleteProduct = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
160
180
  var product;
161
- var prisma = _b.prisma, id = _b.id;
162
- return __generator(this, function (_c) {
163
- switch (_c.label) {
164
- case 0: return [4 /*yield*/, prisma.product.delete({
165
- where: {
166
- id: id,
167
- },
168
- })];
181
+ var id = _b.id, _c = _b.include, include = _c === void 0 ? {
182
+ productCategory: true,
183
+ quotesInvoices: true,
184
+ } : _c, prisma = _b.prisma, _d = _b.queryWhere, queryWhere = _d === void 0 ? {} : _d;
185
+ return __generator(this, function (_e) {
186
+ switch (_e.label) {
187
+ case 0:
188
+ if (!id) {
189
+ throw new Error('Product ID is required');
190
+ }
191
+ if ((queryWhere === null || queryWhere === void 0 ? void 0 : queryWhere.id) && queryWhere.id !== id) {
192
+ throw new Error('ID mismatch between parameter and queryWhere');
193
+ }
194
+ return [4 /*yield*/, prisma.product.delete({
195
+ include: include || null,
196
+ where: __assign({ id: id }, queryWhere),
197
+ })];
169
198
  case 1:
170
- product = _c.sent();
199
+ product = _e.sent();
171
200
  return [2 /*return*/, product];
172
201
  }
173
202
  });
@@ -1,38 +1,55 @@
1
1
  import { ProductCategoryBE } from '../type';
2
- interface GetProductCategoriesArgs {
3
- prisma: any;
2
+ type PrismaClient = any;
3
+ interface ListProductCategoryArgs {
4
+ currentPage?: number;
5
+ include?: any;
6
+ orderBy?: any;
7
+ pageLimit?: number;
8
+ prisma: PrismaClient;
9
+ queryWhere?: any;
4
10
  }
5
- interface GetProductCategoryByIdArgs {
11
+ interface UnitProductCategoryByIdArgs {
6
12
  id: string;
7
- prisma: any;
13
+ include?: any;
14
+ prisma: PrismaClient;
15
+ queryWhere?: any;
8
16
  }
9
- interface PostProductCategoriesArgs {
10
- currentPage: number;
11
- include: {
12
- [key: string]: any;
13
- };
14
- orderBy: {
15
- [key: string]: any;
16
- };
17
- pageLimit: number;
18
- prisma: any;
19
- queryWhere: {
20
- [key: string]: any;
21
- };
22
- }
23
- interface PostProductCategoryArgs {
24
- description: string;
17
+ interface UpdateProductCategoryArgs {
18
+ description?: string;
25
19
  id: string;
20
+ include?: any;
26
21
  name: string;
27
- prisma: any;
22
+ prisma: PrismaClient;
23
+ queryWhere?: any;
28
24
  }
29
25
  interface DeleteProductCategoryArgs {
30
- prisma: any;
31
26
  id: string;
27
+ include?: any;
28
+ prisma: PrismaClient;
29
+ queryWhere?: any;
32
30
  }
33
- export declare const getProductCategories: ({ prisma, }: GetProductCategoriesArgs) => Promise<Array<ProductCategoryBE>>;
34
- export declare const getProductCategoryById: ({ prisma, id, }: GetProductCategoryByIdArgs) => Promise<ProductCategoryBE>;
35
- export declare const postProductCategories: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: PostProductCategoriesArgs) => Promise<Array<ProductCategoryBE>>;
36
- export declare const postProductCategory: ({ description, id, name, prisma, }: PostProductCategoryArgs) => Promise<Array<ProductCategoryBE>>;
37
- export declare const deleteProductCategory: ({ prisma, id, }: DeleteProductCategoryArgs) => Promise<ProductCategoryBE>;
31
+ /**
32
+ * Retrieves a paginated list of product categories
33
+ * @param {ListProductCategoryArgs} args - Object containing prisma client, pagination, filtering, and ordering options
34
+ * @returns {Promise<[number, Array<ProductCategoryBE>]>} Tuple containing total count and array of product categories
35
+ */
36
+ export declare const listProductCategory: ({ currentPage, include, orderBy, pageLimit, prisma, queryWhere, }: ListProductCategoryArgs) => Promise<[number, Array<ProductCategoryBE>]>;
37
+ /**
38
+ * Retrieves a single product category by its ID
39
+ * @param {UnitProductCategoryByIdArgs} args - Object containing prisma client, product category ID, and optional query parameters
40
+ * @returns {Promise<ProductCategoryBE | null>} Product category or null if not found
41
+ */
42
+ export declare const unitProductCategoryById: ({ id, include, prisma, queryWhere, }: UnitProductCategoryByIdArgs) => Promise<ProductCategoryBE | null>;
43
+ /**
44
+ * Creates or updates a product category
45
+ * @param {UpdateProductCategoryArgs} args - Object containing prisma client, product category data, and optional query parameters
46
+ * @returns {Promise<ProductCategoryBE>} Created or updated product category
47
+ */
48
+ export declare const updateProductCategory: ({ description, id, include, name, prisma, queryWhere, }: UpdateProductCategoryArgs) => Promise<ProductCategoryBE>;
49
+ /**
50
+ * Deletes a product category by ID
51
+ * @param {DeleteProductCategoryArgs} args - Object containing prisma client, product category ID, and optional query parameters
52
+ * @returns {Promise<ProductCategoryBE>} Deleted product category
53
+ */
54
+ export declare const deleteProductCategory: ({ id, include, prisma, queryWhere, }: DeleteProductCategoryArgs) => Promise<ProductCategoryBE>;
38
55
  export {};