npm-pkg-hook 1.5.8 → 1.6.0

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.
package/package.json CHANGED
@@ -43,5 +43,5 @@
43
43
  "rm": "rm -rf node_modules package-lock.json && npm i",
44
44
  "test": "echo \"Error: no test specified\" && exit 1"
45
45
  },
46
- "version": "1.5.8"
46
+ "version": "1.6.0"
47
47
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Function that adds 10 to a given number representing minutes.
3
+ * @param {number} num - The number of minutes (between 1 and 60).
4
+ * @returns {string} A string indicating the original number and the result of adding 10 minutes.
5
+ */
6
+ export const addTenMinutes = (num) => {
7
+ if (num >= 50) {
8
+ return `${10 - num} - ${60} min`
9
+ } else {
10
+ return `${num} - ${num + 10} min`
11
+ }
12
+ }
@@ -0,0 +1,30 @@
1
+ function deg2rad (deg) {
2
+ return deg * (Math.PI / 180)
3
+ }
4
+
5
+ // Función para calcular la distancia entre un punto fijo y un punto dado utilizando la fórmula de Haversine
6
+ export function calculateLogLatHaversine (lat1, lon1, lat2, lon2) {
7
+ const radioTierra = 6371 // Radio de la Tierra en kilómetros
8
+ const dLat = deg2rad(lat2 - lat1)
9
+ const dLon = deg2rad(lon2 - lon1)
10
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
11
+ Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
12
+ Math.sin(dLon / 2) * Math.sin(dLon / 2)
13
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
14
+ const distancia = radioTierra * c
15
+ return distancia
16
+ }
17
+ // 768px
18
+ // Coordenadas del punto fijo
19
+ const puntoFijo = { lat: 4.7984084, lon: -75.7338831 }
20
+
21
+ // Array de coordenadas de ejemplo
22
+ const coordenadas = [
23
+ { lat: 4.7954221, lon: -75.730596 }
24
+ ]
25
+
26
+ // Calcular distancias entre cada punto y el punto fijo
27
+ coordenadas.forEach((coordenada, index) => {
28
+ const distancia = calculateLogLatHaversine(puntoFijo.lat, puntoFijo.lon, coordenada.lat, coordenada.lon)
29
+ console.log(`La distancia entre el punto fijo y coordenada ${index + 1} es ${distancia.toFixed(2)} kilómetros`)
30
+ })
@@ -59,4 +59,4 @@ export const getCategoriesWithProduct = (
59
59
  }).filter(Boolean)
60
60
 
61
61
  return findProduct
62
- }
62
+ }
@@ -5,8 +5,11 @@ export * from './useCategoryInStore'
5
5
  export * from './useCategoryStore'
6
6
  export * from './useCatWithProduct'
7
7
  export * from './useManageQueryParams'
8
+ export * from './useDeliveryTime'
8
9
  export * from './statusOpenStores'
9
10
  export * from './newMessageSubscription'
11
+ export * from './useCreateDeliveryTime'
12
+ export * from './addTenMinutes'
10
13
  export * from './useCategoriesProduct'
11
14
  export * from './useLogout'
12
15
  export * from './useStatusOpenStore'
@@ -7,4 +7,4 @@ mutation deleteOneItem($cState: Int, $ShoppingCard: ID) {
7
7
  message
8
8
  }
9
9
  }
10
- `
10
+ `
@@ -1,2 +1,2 @@
1
1
  export * from './useCart'
2
- export * from './useGetCart'
2
+ export * from './useGetCart'
@@ -2,7 +2,7 @@ import { filterKeyObject } from '../../../../utils'
2
2
 
3
3
  const filters = ['__typename']
4
4
 
5
- export const filterDataOptional = (dataOptional) => {
5
+ export const filterDataOptional = (dataOptional) => {
6
6
  if (!Array.isArray(dataOptional)) {
7
7
  throw new Error('Input data is not an array')
8
8
  }
@@ -72,4 +72,4 @@ export const filterExtra = (dataExtra) => {
72
72
  } catch (error) {
73
73
  return []
74
74
  }
75
- }
75
+ }
@@ -52,4 +52,4 @@ query getCatProductsWithProductClient($search: String, $min: Int, $max: Int, $ge
52
52
 
53
53
  }
54
54
  }
55
- `
55
+ `
@@ -75,4 +75,4 @@ getOneCatStore(catStore: $catStore){
75
75
  }
76
76
  }
77
77
  }
78
- `
78
+ `
@@ -0,0 +1,26 @@
1
+ import { useMutation, gql } from '@apollo/client'
2
+
3
+ const CREATE_DELIVERY_TIME = gql`
4
+ mutation CreateDeliveryTime($minutes: Int!) {
5
+ createDeliveryTime(minutes: $minutes) {
6
+ success
7
+ message
8
+ }
9
+ }
10
+ `
11
+
12
+ export const useCreateDeliveryTime = () => {
13
+ const [createDeliveryTimeMutation, { loading, error }] = useMutation(CREATE_DELIVERY_TIME)
14
+
15
+ const createDeliveryTime = async (minutes) => {
16
+ try {
17
+ const { data } = await createDeliveryTimeMutation({ variables: { minutes } })
18
+ return data.createDeliveryTime
19
+ } catch (error) {
20
+ console.error('Error creating delivery time:', error)
21
+ return { success: false, message: 'An error occurred while creating delivery time' }
22
+ }
23
+ }
24
+
25
+ return { createDeliveryTime, loading, error }
26
+ }
@@ -0,0 +1,21 @@
1
+ import { useState } from 'react'
2
+
3
+ /**
4
+ * Custom hook to handle delivery time input validation and formatting.
5
+ * @returns {Object} An object containing state and functions for handling delivery time.
6
+ */
7
+ export const useDeliveryTime = () => {
8
+ const [deliveryTime, setDeliveryTime] = useState('')
9
+ /**
10
+ * Handles changes to the delivery time input.
11
+ * @param {String} value - The input change value.
12
+ */
13
+ const handleDeliveryTimeChange = (value) => {
14
+ setDeliveryTime(value)
15
+ }
16
+
17
+ return {
18
+ deliveryTime,
19
+ handleDeliveryTimeChange
20
+ }
21
+ }
@@ -22,4 +22,4 @@ export const fetchJson = async (...args) => {
22
22
  }
23
23
  throw error
24
24
  }
25
- }
25
+ }
@@ -15,4 +15,4 @@ getOneRating(idStore: $idStore){
15
15
  updateAt
16
16
  }
17
17
  }
18
- `
18
+ `
@@ -1,15 +1,15 @@
1
- export default (d, s, id, jsSrc, cb, onError) => {
2
- const element = d.getElementsByTagName(s)[0]
3
- const fjs = element
4
- let js = element
5
- js = d.createElement(s)
6
- js.id = id
7
- js.src = jsSrc
8
- if (fjs && fjs.parentNode) {
9
- fjs.parentNode.insertBefore(js, fjs)
10
- } else {
11
- d.head.appendChild(js)
12
- }
13
- js.onerror = onError
14
- js.onload = cb
15
- }
1
+ export default (d, s, id, jsSrc, cb, onError) => {
2
+ const element = d.getElementsByTagName(s)[0]
3
+ const fjs = element
4
+ let js = element
5
+ js = d.createElement(s)
6
+ js.id = id
7
+ js.src = jsSrc
8
+ if (fjs && fjs.parentNode) {
9
+ fjs.parentNode.insertBefore(js, fjs)
10
+ } else {
11
+ d.head.appendChild(js)
12
+ }
13
+ js.onerror = onError
14
+ js.onload = cb
15
+ }
@@ -1,7 +1,7 @@
1
- export default (d, id) => {
2
- const element = d.getElementById(id)
3
-
4
- if (element) {
5
- element.parentNode.removeChild(element)
6
- }
7
- }
1
+ export default (d, id) => {
2
+ const element = d.getElementById(id)
3
+
4
+ if (element) {
5
+ element.parentNode.removeChild(element)
6
+ }
7
+ }
@@ -25,4 +25,4 @@ export const useKeyPress = (targetKey) => {
25
25
  }, [targetKey])
26
26
 
27
27
  return keyPressed
28
- }
28
+ }
@@ -0,0 +1,23 @@
1
+ export const findOrderByCodeRef = (data, pCodeRef) => {
2
+ // Iterar sobre cada columna en el objeto data
3
+ for (const column of Object.values(data)) {
4
+ // Buscar el objeto por pCodeRef dentro de la columna actual
5
+ const foundOrder = column.find(order => order.pCodeRef === pCodeRef)
6
+ // Si se encuentra el objeto, devolverlo
7
+ if (foundOrder) {
8
+ return foundOrder
9
+ }
10
+ }
11
+ // Si no se encuentra el objeto en ninguna columna, devolver null
12
+ return null
13
+ }
14
+
15
+ export const isDateInRange = (dateString) => {
16
+ const currentDate = new Date()
17
+ const todayStart = new Date(currentDate.setHours(0, 0, 0, 0))
18
+ const tomorrowStart = new Date(todayStart)
19
+ tomorrowStart.setDate(tomorrowStart.getDate() + 1)
20
+
21
+ const date = new Date(dateString)
22
+ return date >= todayStart && date < tomorrowStart
23
+ }
@@ -1,10 +1,11 @@
1
- import { useState } from 'react'
1
+ import { useEffect, useState } from 'react'
2
2
  import {
3
3
  useGetSale,
4
4
  updateExistingOrders,
5
5
  convertDateFormat,
6
6
  useOrdersFromStore
7
7
  } from '../../hooks'
8
+ import { findOrderByCodeRef, isDateInRange } from './helpers'
8
9
 
9
10
  export const useManageNewOrder = ({
10
11
  client,
@@ -13,6 +14,7 @@ export const useManageNewOrder = ({
13
14
  return { message, duration }
14
15
  },
15
16
  playNotificationSound = () => {},
17
+ setCountOrders = (number) => { return number },
16
18
  sendNotification = ({ title, description, backgroundColor }) => {
17
19
  return {
18
20
  title,
@@ -26,10 +28,24 @@ export const useManageNewOrder = ({
26
28
 
27
29
  const [data] = useOrdersFromStore({
28
30
  idStore,
31
+ search: '',
29
32
  fromDate: convertDateFormat({ start: true }),
30
33
  toDate: convertDateFormat({ start: false })
31
34
  })
32
35
 
36
+ useEffect(() => {
37
+ if (data) {
38
+ const dataOrder = data[KEY_STATUS_ORDER]
39
+ if (Array.isArray(dataOrder) && dataOrder) {
40
+ const filteredOrders = dataOrder.filter(order =>
41
+ isDateInRange(order?.pDatCre) && order?.pSState === 1
42
+ ) ?? []
43
+ setOrders(filteredOrders)
44
+ setCountOrders(filteredOrders.length)
45
+ }
46
+ }
47
+ }, [data])
48
+
33
49
  const [isOpenOrder, setIsOpenOrder] = useState(false)
34
50
  const { getOnePedidoStore } = useGetSale()
35
51
 
@@ -38,7 +54,7 @@ export const useManageNewOrder = ({
38
54
  setOrders(dataOrder)
39
55
  const { pCodeRef } = order || {}
40
56
  if (pCodeRef) {
41
- const isCodeRefExists = orders.some(item => item.pCodeRef === pCodeRef)
57
+ const isCodeRefExists = findOrderByCodeRef(data, pCodeRef)
42
58
  if (isCodeRefExists) {
43
59
  return
44
60
  }
@@ -50,60 +66,7 @@ export const useManageNewOrder = ({
50
66
  }
51
67
  }).then((response) => {
52
68
  console.log(response)
53
- const currentSale = {
54
- __typename: 'StorePedidos',
55
- pdpId: null,
56
- idStore: 'MjcyMDg4ODE0ODUxNTE2NDUw',
57
- pCodeRef,
58
- payMethodPState: 0,
59
- pPRecoger: null,
60
- totalProductsPrice: 36000,
61
- pSState: 1,
62
- pDatCre: '2023-05-23T18:00:36.000Z',
63
- channel: 1,
64
- locationUser: null,
65
- pDatMod: '2023-05-23T18:10:12.000Z',
66
- getAllPedidoStore: [
67
- {
68
- __typename: 'StorePedidos',
69
- pdpId: 'MTg3NzQxMjgyMjQ3NTQ2MzUwMDA=',
70
- pId: null,
71
- idStore: 'MjcyMDg4ODE0ODUxNTE2NDUw',
72
- ShoppingCard: 'Mjc0ODA5NzAzMDAwMDMxNjQwMDA=',
73
- pCodeRef: 'Gi8OfUk9X6',
74
- pPStateP: 1,
75
- payMethodPState: 0,
76
- pPRecoger: null,
77
- pDatCre: '2023-05-23T18:00:36.000Z',
78
- pDatMod: '2023-05-23T18:00:36.000Z',
79
- getAllShoppingCard: {
80
- __typename: 'ShoppingCard',
81
- ShoppingCard: 'Mjc0ODA5NzAzMDAwMDMxNjQwMDA=',
82
- comments: '',
83
- cantProducts: 3,
84
- pId: 'NDM1MzQyMTAzNzYyNDI2MzAwMA==',
85
- productFood: {
86
- __typename: 'ProductFood',
87
- pId: 'MjUwMzIxNzA5NjYzMzk1MTQwMDA=',
88
- carProId: 'MTM2MDQ0NDA3NDI1NzU4MjMwMA==',
89
- colorId: null,
90
- idStore: 'MjcyMDg4ODE0ODUxNTE2NDUw',
91
- pName: 'Hamburguesa mas papas y gaseosa',
92
- ProPrice: 12000,
93
- ProDescuento: '12',
94
- ProDescription: '12312312312',
95
- ValueDelivery: null,
96
- ProImage:
97
- '//front-back-server.fly.dev/static/platos/undefined',
98
- ProStar: 0,
99
- pState: 1,
100
- pDatCre: '2023-05-19T22:42:50.000Z',
101
- pDatMod: '2023-05-19T22:42:50.000Z'
102
- }
103
- }
104
- }
105
- ]
106
- }
69
+ const currentSale = response?.data?.getOnePedidoStore || {}
107
70
  client.cache.modify({
108
71
  fields: {
109
72
  getAllOrdersFromStore (existingOrders = []) {
@@ -115,13 +78,11 @@ export const useManageNewOrder = ({
115
78
  currentSale
116
79
  )
117
80
  const currentOrder = cache[KEY_STATUS_ORDER]
118
- const isCodeRefExists = currentOrder.some(item => item.pCodeRef === pCodeRef)
119
- if (isCodeRefExists) {
120
- return
121
- }
122
- if (currentOrder) {
123
- setOrders(currentOrder)
124
- }
81
+ const filteredOrders = currentOrder.filter(order =>
82
+ isDateInRange(order.pDatCre)
83
+ )
84
+ setOrders(filteredOrders)
85
+ playNotificationSound()
125
86
  return cache
126
87
  } catch (e) {
127
88
  return existingOrders
@@ -2,4 +2,4 @@ export const useOrderClient = () => {
2
2
  return {
3
3
 
4
4
  }
5
- }
5
+ }
@@ -1,20 +1,25 @@
1
+ import { addTenMinutes } from '../../addTenMinutes'
1
2
  import { statusOpenStores } from '../../statusOpenStores'
2
3
 
3
4
  export const getStatusForStores = (stores = []) => {
4
5
  return stores.map((store) => {
6
+ const min = addTenMinutes(store?.deliveryTimeMinutes)
5
7
  if (store?.scheduleOpenAll) {
6
8
  return {
7
9
  ...store,
8
10
  status: { message: '', open: true },
9
- open: 1
11
+ open: 1,
12
+ min: min ?? ''
10
13
  }
11
14
  }
12
15
  const dataSchedules =
13
16
  (store?.getStoreSchedules?.length > 0 && store.getStoreSchedules) || []
14
17
  const status = statusOpenStores({ dataSchedules })
18
+
15
19
  return {
16
20
  ...store,
17
21
  status,
22
+ min: min ?? '',
18
23
  open: status?.open ? 1 : 0
19
24
  }
20
25
  }).sort((a, b) => b.open - a.open)
@@ -16,6 +16,7 @@ query getAllStoreInStore($search: String, $min: Int, $max: Int){
16
16
  cId
17
17
  id
18
18
  dId
19
+ deliveryTimeMinutes
19
20
  ctId
20
21
  catStore
21
22
  neighborhoodStore
@@ -15,6 +15,7 @@ query getStore($id: ID, $idStore: ID){
15
15
  getStore(id: $id, idStore: $idStore){
16
16
  cId
17
17
  id
18
+ deliveryTimeMinutes
18
19
  scheduleOpenAll
19
20
  dId
20
21
  idStore
@@ -1,6 +0,0 @@
1
- {
2
- "recommendations": [
3
- "github.copilot",
4
- "github.copilot-nightly"
5
- ]
6
- }
@@ -1,8 +0,0 @@
1
- {
2
- "cSpell.words": [
3
- "Anauthorized",
4
- "deepmerge",
5
- "Eliminado",
6
- "Pedido"
7
- ]
8
- }