npm-pkg-hook 1.1.5 → 1.1.8

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 (140) hide show
  1. package/.eslintrc.js +19 -113
  2. package/.eslintrc.json +127 -108
  3. package/next.config.js +2 -5
  4. package/package.json +27 -24
  5. package/src/config/client/errors.js +14 -14
  6. package/src/config/client/index.js +1 -1
  7. package/src/hooks/getCategoriesWithProduct/helpers/index.js +7 -0
  8. package/src/hooks/getCategoriesWithProduct/index.js +62 -0
  9. package/src/hooks/getSession/index.js +18 -18
  10. package/src/hooks/index.js +13 -9
  11. package/src/hooks/useAcumulateDate/index.js +1 -1
  12. package/src/hooks/useAnimationFrame/index.js +45 -45
  13. package/src/hooks/useAsideCart/helpers/index.js +22 -0
  14. package/src/hooks/useAsideCart/index.js +156 -0
  15. package/src/hooks/useAsideCart/queries.js +10 -0
  16. package/src/hooks/useBanner/index.js +11 -11
  17. package/src/hooks/useCart/index.js +2 -0
  18. package/src/hooks/useCart/queries.js +164 -0
  19. package/src/hooks/useCart/useCart/helpers/index.js +75 -0
  20. package/src/hooks/useCart/useCart/index.js +411 -0
  21. package/src/hooks/useCart/useGetCart/index.js +31 -0
  22. package/src/hooks/useCatWithProduct/index.js +15 -15
  23. package/src/hooks/useCatWithProduct/queries.js +1 -1
  24. package/src/hooks/useCatWithProductClient/index.js +48 -0
  25. package/src/hooks/useCatWithProductClient/queries.js +55 -0
  26. package/src/hooks/useCategoriesProduct/index.js +12 -12
  27. package/src/hooks/useCategoriesProduct/queries.js +16 -16
  28. package/src/hooks/useCategoryInStore/index.js +39 -36
  29. package/src/hooks/useCategoryInStore/queries.js +78 -78
  30. package/src/hooks/useCategoryStore/index.js +2 -2
  31. package/src/hooks/useChartData/index.js +159 -156
  32. package/src/hooks/useChartData/useChartData/index.js +199 -197
  33. package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -94
  34. package/src/hooks/useCheckbox/index.js +115 -115
  35. package/src/hooks/useClients/index.js +12 -14
  36. package/src/hooks/useClients/queries.js +1 -1
  37. package/src/hooks/useConnection/index.js +20 -21
  38. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +6 -2
  39. package/src/hooks/useCreateProduct/index.js +22 -19
  40. package/src/hooks/useDeleteSubProductOptional/index.js +31 -30
  41. package/src/hooks/useDeleteSubProductOptional/queries.js +10 -10
  42. package/src/hooks/useDessert/helpers/index.js +51 -51
  43. package/src/hooks/useDessert/index.js +56 -65
  44. package/src/hooks/useDevices/index.js +35 -36
  45. package/src/hooks/useDevices/queries.js +19 -19
  46. package/src/hooks/useDropzone/index.js +94 -79
  47. package/src/hooks/useDynamicAuth/index.js +13 -13
  48. package/src/hooks/useDynamicAuth/queries.js +24 -24
  49. package/src/hooks/useEmployee/queries.js +1 -1
  50. package/src/hooks/useEvent/index.js +33 -33
  51. package/src/hooks/useFavoriteStores/index.js +19 -0
  52. package/src/hooks/useFavoriteStores/queries.js +47 -0
  53. package/src/hooks/useFetchJson/index.js +25 -25
  54. package/src/hooks/useFingerprintjs/index.js +172 -176
  55. package/src/hooks/useFormTools/index.js +12 -11
  56. package/src/hooks/useFormatDate/index.js +20 -21
  57. package/src/hooks/useFormatNumberPhone/index.js +9 -9
  58. package/src/hooks/useFullScreenMode/index.js +65 -65
  59. package/src/hooks/useGenerateNumberArray/index.js +17 -17
  60. package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +14 -0
  61. package/src/hooks/useGetFoodRecomended/index.js +33 -0
  62. package/src/hooks/useGetFoodRecomended/queries.js +47 -0
  63. package/src/hooks/useGetMinPrice/index.js +8 -0
  64. package/src/hooks/useGetMinPrice/queries.js +7 -0
  65. package/src/hooks/useGetOneStoreRating/index.js +40 -0
  66. package/src/hooks/useGetOneStoreRating/queries.js +18 -0
  67. package/src/hooks/useGoogleLogin/index.js +160 -161
  68. package/src/hooks/useHover/index.js +29 -29
  69. package/src/hooks/useImageOptimization/index.js +15 -15
  70. package/src/hooks/useImageWeight/index.js +18 -19
  71. package/src/hooks/useImagesStore/index.js +139 -140
  72. package/src/hooks/useImagesStore/queries.js +19 -18
  73. package/src/hooks/useInnerHtml/index.js +39 -38
  74. package/src/hooks/useIntersection/index.js +4 -4
  75. package/src/hooks/useKeypress/index.js +28 -28
  76. package/src/hooks/useLazyScript/index.js +35 -36
  77. package/src/hooks/useLocalSorage/index.js +2 -2
  78. package/src/hooks/useLogout/index.js +23 -23
  79. package/src/hooks/useManageQueryParams/index.js +36 -37
  80. package/src/hooks/useMobile/index.js +39 -38
  81. package/src/hooks/useMutateHeight/index.js +15 -16
  82. package/src/hooks/useOrderClient/index.js +5 -0
  83. package/src/hooks/useOrders/index.js +10 -16
  84. package/src/hooks/useOrders/queries.js +1 -1
  85. package/src/hooks/useProductsFood/index.js +32 -32
  86. package/src/hooks/useProductsFood/queriesStore.js +49 -48
  87. package/src/hooks/useProductsFood/useEditProduct.js +2 -4
  88. package/src/hooks/useProductsFood/usetagsProducts.js +83 -83
  89. package/src/hooks/useProviders/index.js +3 -3
  90. package/src/hooks/useProviders/queries.js +31 -31
  91. package/src/hooks/useProviders/useProvidersCreateStore/index.js +12 -13
  92. package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -24
  93. package/src/hooks/useProvidersStore/index.js +24 -24
  94. package/src/hooks/useProvidersStore/queries.js +31 -31
  95. package/src/hooks/useRatingArrayData/index.js +54 -0
  96. package/src/hooks/{useRatingData → useRatingArrayData}/queries.js +19 -18
  97. package/src/hooks/useReactToPrint/index.js +1120 -1098
  98. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -23
  99. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -48
  100. package/src/hooks/useReport/index.js +9 -9
  101. package/src/hooks/useReport/queries.js +1 -1
  102. package/src/hooks/useRestaurant/index.js +19 -19
  103. package/src/hooks/useRestaurant/queries.js +80 -80
  104. package/src/hooks/useSales/index.js +476 -451
  105. package/src/hooks/useSales/queries.js +14 -15
  106. package/src/hooks/useSales/useGetAllSales/index.js +25 -25
  107. package/src/hooks/useSales/useTotalSales.js +18 -18
  108. package/src/hooks/useSaveAvailableProduct/helpers/index.js +29 -29
  109. package/src/hooks/useSaveAvailableProduct/index.js +16 -16
  110. package/src/hooks/useSaveAvailableProduct/queries.js +1 -1
  111. package/src/hooks/useSchedule/index.js +33 -36
  112. package/src/hooks/useSchedule/index.jsx +22 -22
  113. package/src/hooks/useSchedule/queries.js +34 -35
  114. package/src/hooks/useScheduleData/index.js +123 -171
  115. package/src/hooks/useScroll/index.js +56 -57
  116. package/src/hooks/useScrollRotate/index.js +16 -14
  117. package/src/hooks/useSetSession/index.js +16 -16
  118. package/src/hooks/useSetState/index.js +3 -3
  119. package/src/hooks/useStatusOpenStore/helpers/index.js +101 -102
  120. package/src/hooks/useStatusOpenStore/index.js +172 -173
  121. package/src/hooks/useStatusOrdersClient/helpers/index.js +14 -0
  122. package/src/hooks/useStatusOrdersClient/index.js +17 -0
  123. package/src/hooks/useStatusOrdersClient/queries.js +80 -0
  124. package/src/hooks/useStore/index.js +40 -25
  125. package/src/hooks/useStore/queries.js +162 -136
  126. package/src/hooks/useStoreCalendar/index.js +5 -7
  127. package/src/hooks/useStoreContacts/index.js +16 -16
  128. package/src/hooks/useStoreContacts/queries.js +1 -1
  129. package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
  130. package/src/hooks/useUpdateCart/index.js +34 -28
  131. package/src/hooks/useUpdateExistingOrders/index.js +35 -35
  132. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +38 -37
  133. package/src/hooks/useUser/index.js +1 -1
  134. package/src/hooks/useUser/queries.js +1 -1
  135. package/src/hooks/useWindowSize/index.js +38 -38
  136. package/src/mock/dessert/index.js +16 -16
  137. package/src/mock/index.js +1 -2
  138. package/src/utils/index.js +42 -45
  139. package/src/hooks/useRatingData/index.js +0 -53
  140. package/src/hooks/useSalesClient/index.js +0 -1
@@ -6,24 +6,24 @@ export * from './useCategoryStore'
6
6
  export * from './useCatWithProduct'
7
7
  export * from './useManageQueryParams'
8
8
  export * from './useCategoriesProduct'
9
- export * from './useChartData'
10
9
  export * from './useLogout'
11
10
  export * from './useStatusOpenStore'
12
- export * from './useSchedule'
13
11
  export * from './useScheduleData'
14
- export * from './useImagesStore'
12
+ export * from './useOrders'
15
13
  export * from './useFingerprintjs'
16
14
  export * from './useEmployee'
17
15
  export * from './useCheckbox'
18
16
  export * from './useRemoveExtraProductFoodsOptional'
19
17
  export * from './useDeleteSubProductOptional'
20
- export * from './useRatingData'
18
+ export * from './useGetOneStoreRating'
19
+ export * from './useFavoriteStores'
20
+ export * from './useAsideCart'
21
+ export * from './useRatingArrayData'
21
22
  export * from './useChartData'
22
23
  export * from './useDevices'
23
- export * from './useSales'
24
24
  export * from './useClients'
25
25
  export * from './useScroll'
26
- export * from './useOrders'
26
+ export * from './useStatusOrdersClient'
27
27
  export * from './useUpdateExistingOrders'
28
28
  export * from './useConnection'
29
29
  export * from './useCreateProduct'
@@ -51,19 +51,23 @@ export * from './useProductsFood'
51
51
  export * from './useProductsFood/usetagsProducts'
52
52
  export * from './useReactToPrint'
53
53
  export * from './useReport'
54
- // hola
54
+ export * from './useSales/useTotalSales'
55
+ export * from './useOrderClient'
55
56
  export * from './useStoreContacts'
56
57
  export * from './useRestaurant'
57
58
  export * from './useSales'
58
59
  export * from './useSales/useGetSale'
59
- export * from './useSales/useTotalSales'
60
+ export * from './useGetMinPrice'
61
+ export * from './useCatWithProductClient'
62
+ export * from './useGetFoodRecomended'
60
63
  export * from './useSaveAvailableProduct'
61
64
  export * from './useSchedule'
62
65
  export * from './useSetState'
63
66
  export * from './useStore'
64
67
  export * from './useStoreCalendar'
68
+ export * from './getCategoriesWithProduct'
65
69
  export * from './useTimeAgo/useTimeAgo'
66
70
  export * from './useUpdateCart'
67
71
  export * from './useUpdateExtProductFoodsSubOptional'
68
72
  export * from './useUser'
69
-
73
+ export * from './useCart'
@@ -1,4 +1,3 @@
1
-
2
1
  const data = [
3
2
  { x: '2021-10-17T14:38:45.540Z', y: 2 }
4
3
  ]
@@ -13,4 +12,5 @@ export function groupDates (arr) {
13
12
  }, 0)
14
13
  return total
15
14
  }
15
+ // eslint-disable-next-line no-unused-vars
16
16
  const result = groupDates(data)
@@ -1,45 +1,45 @@
1
- import { useEffect, useRef } from "react"
2
-
3
- export const useAnimationFrame = (callback, start, end, duration = 1000) => {
4
- const functionRef = useRef()
5
- const delta = Math.abs(start - end)
6
- const frameCount = Math.ceil(60 * (duration / 1000))
7
- const iteration = useRef(frameCount)
8
- useEffect(() => {
9
- const animate = (rafId) => {
10
- if (iteration.current <= 0) {
11
- cancelAnimationFrame(rafId)
12
- iteration.current = frameCount
13
- }
14
-
15
- callback(Math.max(delta / iteration.current, 1))
16
- iteration.current--
17
- }
18
-
19
- if (delta > 0) functionRef.current = requestAnimationFrame(animate)
20
-
21
- return () => {return cancelAnimationFrame(functionRef.current)}
22
- }, [callback, delta, frameCount, iteration])
23
- }
24
-
25
- // const Counter = ({ numeral = 0 }) => {
26
- // const [currentValue, setCurrentValue] = useState(0)
27
- // const fxOperator = currentValue > numeral ? 'subtraction' : 'addition'
28
-
29
- // useAnimationFrame(
30
- // (diffValue) => {
31
- // // Pass on a function to the setter of the state
32
- // // to make sure we always have the latest state
33
- // setCurrentValue((prevCount) => {
34
- // return fxOperator === 'addition'
35
- // ? prevCount + diffValue
36
- // : prevCount - diffValue
37
- // }
38
- // )
39
- // },
40
- // currentValue,
41
- // numeral,
42
- // 300
43
- // )
44
- // return <>{new Intl.NumberFormat().format(Math.round(currentValue))}</>
45
- // }
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ export const useAnimationFrame = (callback, start, end, duration = 1000) => {
4
+ const functionRef = useRef()
5
+ const delta = Math.abs(start - end)
6
+ const frameCount = Math.ceil(60 * (duration / 1000))
7
+ const iteration = useRef(frameCount)
8
+ useEffect(() => {
9
+ const animate = (rafId) => {
10
+ if (iteration.current <= 0) {
11
+ cancelAnimationFrame(rafId)
12
+ iteration.current = frameCount
13
+ }
14
+
15
+ callback(Math.max(delta / iteration.current, 1))
16
+ iteration.current--
17
+ }
18
+
19
+ if (delta > 0) functionRef.current = requestAnimationFrame(animate)
20
+
21
+ return () => { return cancelAnimationFrame(functionRef.current) }
22
+ }, [callback, delta, frameCount, iteration])
23
+ }
24
+
25
+ // const Counter = ({ numeral = 0 }) => {
26
+ // const [currentValue, setCurrentValue] = useState(0)
27
+ // const fxOperator = currentValue > numeral ? 'subtraction' : 'addition'
28
+
29
+ // useAnimationFrame(
30
+ // (diffValue) => {
31
+ // // Pass on a function to the setter of the state
32
+ // // to make sure we always have the latest state
33
+ // setCurrentValue((prevCount) => {
34
+ // return fxOperator === 'addition'
35
+ // ? prevCount + diffValue
36
+ // : prevCount - diffValue
37
+ // }
38
+ // )
39
+ // },
40
+ // currentValue,
41
+ // numeral,
42
+ // 300
43
+ // )
44
+ // return <>{new Intl.NumberFormat().format(Math.round(currentValue))}</>
45
+ // }
@@ -0,0 +1,22 @@
1
+ export const calculateTotalPrice = (shoppingCardData) => {
2
+ if (Array.isArray(shoppingCardData) && shoppingCardData.length) {
3
+ return shoppingCardData.reduce((accumulator, currentItem) => {
4
+ const { productFood = {}, cantProducts } = currentItem || {}
5
+ const { ProPrice = 0, ValueDelivery = 0 } = productFood || {}
6
+
7
+ const pricePerProduct = ProPrice * cantProducts
8
+ const deliveryCost = ValueDelivery || 0
9
+ const ExtProductFoodsAll = currentItem.ExtProductFoodsAll || []
10
+
11
+ const extraPriceSum = ExtProductFoodsAll.reduce((extraAccumulator, extraFood) => {
12
+ if (Number.isInteger(extraFood.newExtraPrice)) {
13
+ return extraAccumulator + extraFood.newExtraPrice
14
+ }
15
+ return extraAccumulator
16
+ }, 0)
17
+
18
+ return accumulator + pricePerProduct + deliveryCost + extraPriceSum
19
+ }, 0)
20
+ }
21
+ return 0
22
+ }
@@ -0,0 +1,156 @@
1
+ import {
2
+ useState,
3
+ useEffect,
4
+ useMemo
5
+ } from 'react'
6
+ import { useMutation } from '@apollo/client'
7
+ import { DELETE_ONE_ITEM_SHOPPING_PRODUCT } from './queries'
8
+ import { useCart, useGetCart } from '../useCart'
9
+ import { useManageQueryParams } from '../useManageQueryParams'
10
+ import { calculateTotalPrice } from './helpers'
11
+ export * from './helpers'
12
+ /**
13
+ * Custom hook for managing the shopping cart functionality.
14
+ * @param {Object} props - Props to control various UI elements.
15
+ * @param {function} props.setCountItemProduct - Function to set the count of items in the cart.
16
+ * @param {function} props.setAlertBox - Function to set an alert message.
17
+ * @param {function} props.handleMenu - Function to handle cart menu visibility.
18
+ * @returns {Object} An object with various shopping cart-related functions and data.
19
+ */
20
+ export const useAsideCart = ({
21
+ openModalProduct = false,
22
+ setCountItemProduct = () => { },
23
+ setAlertBox = () => { },
24
+ setOpenModalProduct = () => { },
25
+ handleMenu = () => { }
26
+ } = {}) => {
27
+ const { getOneProduct } = useCart({
28
+ handleMenu,
29
+ openModalProduct,
30
+ setOpenModalProduct
31
+ })
32
+
33
+ const { handleQuery } = useManageQueryParams()
34
+
35
+ const [totalProductPrice, setTotalProductPrice] = useState(0)
36
+
37
+ const [dataShoppingCard, { loading }] = useGetCart({ setCountItemProduct })
38
+ console.log({ dataShoppingCard })
39
+
40
+ // Lógica de transformación de los datos
41
+ const result2 = useMemo(() => {
42
+ if (!loading && dataShoppingCard) {
43
+ return dataShoppingCard.reduce((r, a) => {
44
+ const storeName = a.getStore?.storeName
45
+ if (storeName) {
46
+ r[storeName] = r[storeName] || []
47
+ r[storeName].push(a)
48
+ }
49
+ return r
50
+ }, {})
51
+ }
52
+ return {}
53
+ }, [loading, dataShoppingCard])
54
+
55
+ // Obtener dataProduct2 directamente
56
+ const key = useMemo(() => {
57
+ return Object.keys(result2)
58
+ }, [result2])
59
+
60
+ useEffect(() => {
61
+ const totalPrice = calculateTotalPrice(dataShoppingCard)
62
+ setTotalProductPrice(Math.abs(totalPrice))
63
+ }, [dataShoppingCard])
64
+
65
+ console.log(dataShoppingCard)
66
+ const [deleteOneItem] = useMutation(DELETE_ONE_ITEM_SHOPPING_PRODUCT, {
67
+ onCompleted: data => {
68
+ setAlertBox({ message: data?.deleteOneItem?.message })
69
+
70
+ if (dataShoppingCard?.length === 1 && data?.deleteOneItem?.success) {
71
+ setAlertBox({ message: 'Tu carrito está vacío' }) // Ajusta el mensaje en español
72
+ handleMenu(false) // Oculta el menú del carrito
73
+ }
74
+ }
75
+ })
76
+
77
+ const handleEditProduct = async (item) => {
78
+ const pId = item?.pId || null
79
+ if (pId) handleQuery('plato', pId)
80
+ if (pId) {
81
+ const product = { pId, intoCart: true }
82
+ getOneProduct(product)
83
+ }
84
+ }
85
+ /**
86
+ * Handle the deletion of a shopping cart item.
87
+ * @param {Object} item - The item to be deleted from the shopping cart.
88
+ */
89
+ const handleDeleteItemShopping = async (item) => {
90
+ try {
91
+ const { cState, ShoppingCard } = item
92
+ await deleteOneItem({
93
+ variables: {
94
+ cState,
95
+ ShoppingCard
96
+ },
97
+ update: (cache, { data }) => {
98
+ const success = data?.deleteOneItem?.success
99
+ if (success && ShoppingCard) {
100
+ cache.modify({
101
+ fields: {
102
+ getAllShoppingCard (existingCart, { readField }) {
103
+ if (Array.isArray(existingCart) && existingCart) {
104
+ if (existingCart.length === 1) {
105
+ setCountItemProduct(0)
106
+ }
107
+ const updatedCart = {
108
+ ...existingCart,
109
+ ...existingCart?.filter(product =>
110
+ readField('ShoppingCard', product) !== ShoppingCard
111
+ )
112
+ }
113
+ if (typeof updatedCart === 'object' && updatedCart !== null) {
114
+ const newLength = Object.keys(updatedCart)
115
+ if (updatedCart && newLength) {
116
+ setCountItemProduct(Object.keys(updatedCart).length)
117
+ }
118
+ }
119
+ return updatedCart
120
+ } else {
121
+ return []
122
+ }
123
+ }
124
+ }
125
+ })
126
+ }
127
+ }
128
+ })
129
+ } catch (error) {
130
+ setAlertBox({ message: 'Error borranto el item. Por favor intenta nuevamente.', color: 'error' })
131
+ }
132
+ }
133
+ /**
134
+ * Calculate the total price of a product.
135
+ * @param {number} ProPrice - The price of the product.
136
+ * @param {number} ProDelivery - The delivery cost of the product.
137
+ * @param {number} cant - The quantity of the product.
138
+ * @returns {number} The calculated total price.
139
+ */
140
+ const sumProduct = (ProPrice, ProDelivery, cant) => {
141
+ const price = parseInt(ProPrice)
142
+ const priceFinal = cant * price
143
+ const delivery = parseInt(ProDelivery || 0)
144
+ return delivery ? priceFinal + delivery : priceFinal
145
+ }
146
+
147
+ return {
148
+ key,
149
+ totalProductPrice,
150
+ result2,
151
+ dataShoppingCard,
152
+ handleDeleteItemShopping,
153
+ handleEditProduct,
154
+ sumProduct
155
+ }
156
+ }
@@ -0,0 +1,10 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const DELETE_ONE_ITEM_SHOPPING_PRODUCT = gql`
4
+ mutation deleteOneItem($cState: Int, $ShoppingCard: ID) {
5
+ deleteOneItem(cState: $cState, ShoppingCard: $ShoppingCard){
6
+ success
7
+ message
8
+ }
9
+ }
10
+ `
@@ -5,15 +5,15 @@ import { useStore } from '../useStore'
5
5
  export const useBanner = () => {
6
6
  const [store, { loading: loaStore }] = useStore()
7
7
 
8
- const {
9
- data,
10
- loading,
11
- error
12
- } = useQuery(GET_ONE_BANNER_STORE, {
13
- context: { clientName: 'admin-server' },
14
- variables: {
15
- idStore: !loaStore && ''
16
- }
17
- })
18
- return [data?.getOneBanners, { loading, error }]
8
+ const {
9
+ data,
10
+ loading,
11
+ error
12
+ } = useQuery(GET_ONE_BANNER_STORE, {
13
+ context: { clientName: 'admin-server' },
14
+ variables: {
15
+ idStore: !loaStore && store?.idStore
16
+ }
17
+ })
18
+ return [data?.getOneBanners, { loading, error }]
19
19
  }
@@ -0,0 +1,2 @@
1
+ export * from './useCart'
2
+ export * from './useGetCart'
@@ -0,0 +1,164 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ export const CREATE_SHOPPING_CARD = gql`
4
+ mutation registerShoppingCard(
5
+ $input: IShoppingCard
6
+ $idSubArray: IID_SUB_ITEMS
7
+ ) {
8
+ registerShoppingCard(input: $input, idSubArray: $idSubArray) {
9
+ ShoppingCard
10
+ id
11
+ pId
12
+ subProductsId
13
+ ShoppingCardRefCode
14
+ uuid
15
+ discountCardProduct
16
+ idUser
17
+ cName
18
+ idStore
19
+ cState
20
+ cDatCre
21
+ cDatMod
22
+ csDescription
23
+ cantProducts
24
+ comments
25
+ }
26
+ }
27
+ `
28
+
29
+ export const GET_ALL_SHOPPING_CARD = gql`
30
+ query getAllShoppingCard {
31
+ getAllShoppingCard {
32
+ ShoppingCard
33
+ cState
34
+ idStore
35
+ refCodePid
36
+ pId
37
+ comments
38
+ salesExtProductFoodOptional {
39
+ pId
40
+ opExPid
41
+ OptionalProName
42
+ state
43
+ code
44
+ required
45
+ numbersOptionalOnly
46
+ pDatCre
47
+ pDatMod
48
+ saleExtProductFoodsSubOptionalAll {
49
+ pId
50
+ opExPid
51
+ idStore
52
+ opSubExPid
53
+ OptionalSubProName
54
+ exCodeOptionExtra
55
+ exCode
56
+ state
57
+ pDatCre
58
+ pDatMod
59
+ }
60
+ }
61
+ ExtProductFoodsAll {
62
+ pId
63
+ exPid
64
+ exState
65
+ extraName
66
+ extraPrice
67
+ quantity
68
+ newExtraPrice
69
+ state
70
+ pDatCre
71
+ pDatMod
72
+ }
73
+ productFood {
74
+ pId
75
+ carProId
76
+ sizeId
77
+ colorId
78
+ idStore
79
+ cId
80
+ caId
81
+ dId
82
+ ctId
83
+ tpId
84
+ fId
85
+ pName
86
+ ProPrice
87
+ ProDescuento
88
+ ProUniDisponibles
89
+ ProDescription
90
+ ValueDelivery
91
+ ProProtegido
92
+ ProAssurance
93
+ ProImage
94
+ ProStar
95
+ ProWidth
96
+ ProHeight
97
+ ProLength
98
+ ProWeight
99
+ ProQuantity
100
+ ProOutstanding
101
+ ProDelivery
102
+ ProVoltaje
103
+ pState
104
+ sTateLogistic
105
+ pDatCre
106
+ pDatMod
107
+ }
108
+ cantProducts
109
+ getStore {
110
+ idStore
111
+ cId
112
+ id
113
+ dId
114
+ ctId
115
+ catStore
116
+ neighborhoodStore
117
+ Viaprincipal
118
+ storeOwner
119
+ storeName
120
+ emailStore
121
+ storePhone
122
+ socialRaz
123
+ Image
124
+ banner
125
+ documentIdentifier
126
+ uPhoNum
127
+ ULocation
128
+ upLat
129
+ upLon
130
+ uState
131
+ siteWeb
132
+ description
133
+ NitStore
134
+ typeRegiments
135
+ typeContribute
136
+ secVia
137
+ addressStore
138
+ createdAt
139
+ pais {
140
+ cId
141
+ cName
142
+ cCalCod
143
+ cState
144
+ cDatCre
145
+ cDatMod
146
+ }
147
+ city {
148
+ ctId
149
+ dId
150
+ cName
151
+ cState
152
+ }
153
+ department {
154
+ dId
155
+ cId
156
+ dName
157
+ dState
158
+ dDatCre
159
+ dDatMod
160
+ }
161
+ }
162
+ }
163
+ }
164
+ `
@@ -0,0 +1,75 @@
1
+ import { filterKeyObject } from '../../../../utils'
2
+
3
+ const filters = ['__typename']
4
+
5
+ export const filterDataOptional = (dataOptional) => {
6
+ if (!Array.isArray(dataOptional)) {
7
+ throw new Error('Input data is not an array')
8
+ }
9
+
10
+ try {
11
+ const filteredDataOptional = dataOptional.map(item => {
12
+ const checkedSubOptions = item?.ExtProductFoodsSubOptionalAll?.filter(subItem => subItem.check === true)
13
+ const ExtProductFoodsSubOptionalAll = checkedSubOptions?.map(subItemsOptional => {
14
+ return {
15
+ ...filterKeyObject(subItemsOptional, filters)
16
+ }
17
+ })
18
+ return {
19
+ ...filterKeyObject(item, filters),
20
+ ExtProductFoodsSubOptionalAll
21
+ }
22
+ }).filter(item => item?.ExtProductFoodsSubOptionalAll.length > 0)
23
+ return filteredDataOptional
24
+ } catch (error) {
25
+ console.error('An error occurred while filtering data:', error.message)
26
+ return []
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Valida los requerimientos de elementos opcionales.
32
+ * @param {Array} filteredDataOptional - El array de datos a validar.
33
+ * @returns {boolean} Devuelve true si se cumplen los requerimientos, de lo contrario, false.
34
+ */
35
+ export function validateRequirements (filteredDataOptional) {
36
+ if (Array.isArray(filteredDataOptional)) {
37
+ for (const item of filteredDataOptional) {
38
+ if (item.required === 1) {
39
+ const checkedSubOptions = item?.ExtProductFoodsSubOptionalAll.filter(subItem => subItem.check === true)
40
+ if (checkedSubOptions.length !== item.numbersOptionalOnly) {
41
+ return true
42
+ }
43
+ }
44
+ }
45
+ }
46
+ return false
47
+ }
48
+
49
+ export function validateExtraProducts (dataExtra) {
50
+ const requiredItems = dataExtra.filter(item => item.exState === 1)
51
+
52
+ if (requiredItems.length > 0) {
53
+ const hasSelectedRequiredProduct = requiredItems.some(item => item.quantity > 0)
54
+ return hasSelectedRequiredProduct
55
+ }
56
+
57
+ return true
58
+ }
59
+
60
+ export const filterExtra = (dataExtra) => {
61
+ if (!Array.isArray(dataExtra)) {
62
+ throw new Error('Input data is not an array')
63
+ }
64
+ try {
65
+ const dataExtraFiltered = dataExtra.filter(extra => extra.quantity !== 0)
66
+ .map(extra => {
67
+ return {
68
+ ...filterKeyObject(extra, filters)
69
+ }
70
+ })
71
+ return dataExtraFiltered
72
+ } catch (error) {
73
+ return []
74
+ }
75
+ }