npm-pkg-hook 1.10.1 β†’ 1.10.2

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
@@ -47,5 +47,5 @@
47
47
  "rm": "rm -rf node_modules package-lock.json && npm i",
48
48
  "test": "echo \"Error: no test specified\" && exit 1"
49
49
  },
50
- "version": "1.10.1"
50
+ "version": "1.10.2"
51
51
  }
@@ -1,5 +1,4 @@
1
1
  export async function handleLogin (body) {
2
- console.log("πŸš€ ~ handleLogin ~ body:", body)
3
2
  const response = await fetch(`${process.env.URL_BASE}/api/auth/login`, {
4
3
  method: 'POST',
5
4
  headers: { 'Content-Type': 'application/json' },
@@ -10,6 +10,7 @@ export * from './useModules'
10
10
  export * from './getTotalHours'
11
11
  export * from './useUpdateMultipleProducts'
12
12
  export * from './useTokenCards'
13
+ export * from './useStoreTable/index'
13
14
  export * from './useSubscriptionValidation'
14
15
  export * from './convertToMilitaryTime'
15
16
  export * from './useRoles'
@@ -13,7 +13,7 @@ export const useChartDataAllOrders = ({
13
13
  2: 'PROCESSING',
14
14
  3: 'READY',
15
15
  4: 'CONCLUDES',
16
- 5: 'RECHAZADOS'
16
+ 5: 'REJECTED'
17
17
  }
18
18
 
19
19
  // Objeto para almacenar los totales por estado
@@ -134,8 +134,8 @@ mutation registerShoppingCard($input: IShoppingCard, $idSubArray: IID_SUB_ITEMS
134
134
  }
135
135
  `
136
136
  export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
137
- mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change: Float, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
138
- registerSalesStore(input: $input, id: $id, idStore: $idStore, pCodeRef: $pCodeRef, change: $change, valueDelivery: $valueDelivery, payMethodPState: $payMethodPState, pickUp: $pickUp, totalProductsPrice: $totalProductsPrice, idSubArray: $idSubArray){
137
+ mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $tableId: ID, $pCodeRef: String, $change: Float, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
138
+ registerSalesStore(input: $input, id: $id, idStore: $idStore, tableId: $tableId, pCodeRef: $pCodeRef, change: $change, valueDelivery: $valueDelivery, payMethodPState: $payMethodPState, pickUp: $pickUp, totalProductsPrice: $totalProductsPrice, idSubArray: $idSubArray){
139
139
  ShoppingCard {
140
140
  ShoppingCard
141
141
  id
@@ -12,6 +12,7 @@ import { useStore } from '../useStore'
12
12
  import { useTagsProducts } from './../useProductsFood/usetagsProducts'
13
13
  import { useEditImageProduct } from './helpers/useEditImageProduct'
14
14
  import { getCatProductsWithProduct } from './helpers/manageCacheDataCatProduct'
15
+ import { assignWith } from 'lodash'
15
16
  export * from './helpers'
16
17
 
17
18
  export const useCreateProduct = ({
@@ -219,6 +220,19 @@ export const useCreateProduct = ({
219
220
  carProId: ''
220
221
  })
221
222
  })
223
+ const { errors } = res ?? {
224
+ errors: []
225
+ }
226
+ if (errors?.length > 0) {
227
+ errors.forEach(error => {
228
+ sendNotification({
229
+ backgroundColor: 'error',
230
+ title: 'Error',
231
+ description: error.message
232
+ })
233
+ })
234
+ return
235
+ }
222
236
  if (image !== null) {
223
237
  try {
224
238
  await setImageProducts({
@@ -240,6 +254,7 @@ export const useCreateProduct = ({
240
254
  setPid(res?.data?.updateProductFoods?.data?.pId ?? null)
241
255
  return res
242
256
  } catch (error) {
257
+ console.log("πŸš€ ~ handleRegister ~ error:", error)
243
258
  setAlertBox({ message: 'Ha ocurrido un error', duration: 7000 })
244
259
  }
245
260
  }
@@ -1,35 +1,2 @@
1
- import { useState, useEffect } from 'react'
2
- import { useQuery } from '@apollo/client'
3
- import { GET_ALL_DEVICES } from './queries'
4
- import { useFormatDate } from '../useFormatDate'
5
-
6
- export const useDevices = () => {
7
- const { data, loading } = useQuery(GET_ALL_DEVICES, {
8
- onError: (error) => {
9
- console.error(error)
10
- }
11
- })
12
- const [deviceId, setDeviceId] = useState(false)
13
- const [date, setDate] = useState('')
14
-
15
- useEffect(() => {
16
- if (window) {
17
- setDeviceId(window.localStorage.getItem('deviceid'))
18
- }
19
- }, [])
20
-
21
- // FunciΓ³n para formatear la fecha
22
- const formatDate = useFormatDate({ date })
23
-
24
- const updateDate = (newDate) => {
25
- setDate(newDate)
26
- }
27
- return {
28
- data: data?.getDeviceUsers || [],
29
- date,
30
- deviceId,
31
- formatDate,
32
- loading,
33
- updateDate
34
- }
35
- }
1
+ export * from './useGetDevices'
2
+ export * from './useRegisterDevices'
@@ -0,0 +1,35 @@
1
+ import { useState, useEffect } from 'react'
2
+ import { useQuery } from '@apollo/client'
3
+ import { GET_ALL_DEVICES } from './queries'
4
+ import { useFormatDate } from '../useFormatDate'
5
+
6
+ export const useDevices = () => {
7
+ const { data, loading } = useQuery(GET_ALL_DEVICES, {
8
+ onError: (error) => {
9
+ console.error(error)
10
+ }
11
+ })
12
+ const [deviceId, setDeviceId] = useState(false)
13
+ const [date, setDate] = useState('')
14
+
15
+ useEffect(() => {
16
+ if (window) {
17
+ setDeviceId(window.localStorage.getItem('deviceid'))
18
+ }
19
+ }, [])
20
+
21
+ // FunciΓ³n para formatear la fecha
22
+ const formatDate = useFormatDate({ date })
23
+
24
+ const updateDate = (newDate) => {
25
+ setDate(newDate)
26
+ }
27
+ return {
28
+ data: data?.getDeviceUsers || [],
29
+ date,
30
+ deviceId,
31
+ formatDate,
32
+ loading,
33
+ updateDate
34
+ }
35
+ }
@@ -0,0 +1,75 @@
1
+ import { useMutation, gql } from '@apollo/client'
2
+
3
+ /**
4
+ * GraphQL mutation para registrar un nuevo dispositivo
5
+ */
6
+ const REGISTER_DEVICE_USER = gql`
7
+ mutation RegisterDeviceUser($input: DeviceUserInput!) {
8
+ newRegisterDeviceUser(input: $input) {
9
+ success
10
+ message
11
+ data {
12
+ dId
13
+ id
14
+ deviceId
15
+ deviceName
16
+ locationFormat
17
+ type
18
+ short_name
19
+ platform
20
+ version
21
+ dState
22
+ DatCre
23
+ DatMod
24
+ }
25
+ errors {
26
+ path
27
+ message
28
+ type
29
+ context {
30
+ limit
31
+ value
32
+ label
33
+ key
34
+ }
35
+ }
36
+ }
37
+ }
38
+ `
39
+
40
+ /**
41
+ * Custom hook para la mutaciΓ³n RegisterDeviceUser
42
+ * @returns {Object} - FunciΓ³n para registrar el dispositivo y el estado de la operaciΓ³n
43
+ */
44
+ export const useRegisterDeviceUser = () => {
45
+ const [registerDeviceUser, { loading, error, data }] = useMutation(REGISTER_DEVICE_USER)
46
+
47
+ /**
48
+ * FunciΓ³n para manejar la mutaciΓ³n
49
+ * @param {Object} input - Datos del dispositivo a registrar
50
+ * @returns {Promise<Object>} - Resultado de la operaciΓ³n
51
+ */
52
+ const handleRegisterDeviceUser = async (input) => {
53
+ try {
54
+ const result = await registerDeviceUser({ variables: { input } })
55
+
56
+ if (result.data?.newRegisterDeviceUser?.success) {
57
+ return { success: true, data: result.data.newRegisterDeviceUser.data }
58
+ } else {
59
+ return {
60
+ success: false,
61
+ errors: result.data?.newRegisterDeviceUser?.errors || []
62
+ }
63
+ }
64
+ } catch (err) {
65
+ console.error('Error while registering device user:', err)
66
+ return { success: false, errors: [{ message: err.message }] }
67
+ }
68
+ }
69
+
70
+ return [handleRegisterDeviceUser, {
71
+ loading,
72
+ error,
73
+ data
74
+ }]
75
+ }
@@ -23,7 +23,6 @@ export const __NEXTAUTH = {
23
23
 
24
24
  export async function signOutAuth (options) {
25
25
  const { callbackUrl = window.location.href, reload = true } = options ?? {}
26
- console.log('πŸš€ ~ signOutAuth ~ options:', options)
27
26
  const baseUrl = apiBaseUrl(__NEXTAUTH)
28
27
  const fetchOptions = {
29
28
  method: 'post',
@@ -0,0 +1 @@
1
+ export * from './validateModules'
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Validates and filters modules based on the "read" permission.
3
+ * If a module's view does not have "read" permission in the permissions object, the module is removed.
4
+ *
5
+ * @param {Array} modules - List of modules to validate.
6
+ * @param {Object} permissions - Permissions object mapping views to their allowed actions.
7
+ * @returns {Array} - Filtered list of valid modules.
8
+ */
9
+ export const validateModules = (modules = [], permissions = {}) => {
10
+ return modules
11
+ .map(module => {
12
+ // Check if the main module's view has "read" permission
13
+ const hasReadPermission = permissions[module.view]?.includes('read')
14
+
15
+ // Validate and filter subModules if they exist
16
+ const validSubModules = module.subModules?.filter(subModule =>
17
+ permissions[subModule.view]?.includes('read')
18
+ ) || []
19
+
20
+ // If the module or its subModules don't have read permission, exclude it
21
+ if (!hasReadPermission && validSubModules.length === 0) {
22
+ return null
23
+ }
24
+
25
+ // Return the module with its valid subModules
26
+ return { ...module, subModules: validSubModules }
27
+ })
28
+ .filter(Boolean) // Remove null values
29
+ }
@@ -1,4 +1,5 @@
1
1
  import { gql, useQuery } from '@apollo/client'
2
+ import { validateModules } from './helpers/validateModules'
2
3
 
3
4
  const GET_MODULES = gql`
4
5
  query GetModules {
@@ -8,22 +9,37 @@ const GET_MODULES = gql`
8
9
  mPath
9
10
  mPriority
10
11
  mIcon
12
+ view
11
13
  subModules {
12
14
  smId
13
15
  smName
14
16
  smPath
17
+ view
15
18
  smState
16
19
  }
17
20
  }
18
21
  }
19
22
  `
20
23
 
21
- export const useModules = () => {
22
- const { loading, error, data } = useQuery(GET_MODULES)
24
+ export const useModules = (dataUser = {}) => {
25
+ const { role } = dataUser ?? {
26
+ role: {
27
+ permissions: {}
28
+ }
29
+ }
30
+ const {
31
+ loading,
32
+ error,
33
+ data
34
+ } = useQuery(GET_MODULES)
35
+
36
+ const permissions = role?.permissions ?? {}
37
+
38
+ const filteredModules = validateModules(data ? data.modules : [], permissions)
23
39
 
24
40
  return {
25
41
  loading,
26
42
  error,
27
- modules: data ? data.modules : []
43
+ modules: data ? filteredModules : []
28
44
  }
29
45
  }
@@ -274,7 +274,7 @@ query getAllOrdersFromStore(
274
274
  }
275
275
  }
276
276
  }
277
- RECHAZADOS {
277
+ REJECTED {
278
278
  pdpId
279
279
  idStore
280
280
  pCodeRef
@@ -373,6 +373,12 @@ export const useSales = ({
373
373
  },
374
374
  [productsFood]
375
375
  )
376
+ const paymentMethod = (state, action) => {
377
+ return {
378
+ ...state,
379
+ payMethodPState: action.payload
380
+ }
381
+ }
376
382
  const PRODUCT = (state, action) => {
377
383
  const productExist = state.PRODUCT.find((items) => {
378
384
  return items.pId === action.id
@@ -461,22 +467,13 @@ export const useSales = ({
461
467
  return {
462
468
  ...state
463
469
  }
464
- case 'PAYMENT_METHOD_TRANSACTION':
465
- return {
466
- ...state,
467
- payMethodPState: 1
468
- }
469
- case 'PAYMENT_METHOD_MONEY':
470
- return {
471
- ...state,
472
- payMethodPState: 0
473
- }
470
+ case 'PAYMENT_METHOD': return paymentMethod(state, action)
471
+
474
472
  default:
475
473
  return state
476
474
  }
477
475
  }
478
476
  const [data, dispatch] = useReducer(PRODUCT, initialStateSales, initializer)
479
- console.log({ data })
480
477
 
481
478
  const handleRemoveValue = useCallback(({ name, value, pId }) => {
482
479
  setValues({
@@ -972,13 +969,24 @@ export const useSales = ({
972
969
  }
973
970
  return cadena || 0
974
971
  }
972
+ const {
973
+ change,
974
+ valueDelivery,
975
+ tableId
976
+ } = values || {
977
+ change: 0,
978
+ valueDelivery: 0,
979
+ tableId: null,
980
+ cliId: null
981
+ }
975
982
  return registerSalesStore({
976
983
  variables: {
977
984
  input: finalArrayProduct || [],
978
985
  id: values?.cliId,
979
986
  pCodeRef: code,
980
- change: convertInteger(values.change),
981
- valueDelivery: convertInteger(values.valueDelivery),
987
+ tableId,
988
+ change: convertInteger(change),
989
+ valueDelivery: convertInteger(valueDelivery),
982
990
  payMethodPState: data.payMethodPState,
983
991
  pickUp: 1,
984
992
  discount: discount.discount || 0,
@@ -1000,6 +1008,8 @@ export const useSales = ({
1000
1008
  client.writeQuery({ query: GET_ALL_COUNT_SALES, data: { getTodaySales: data.countSales.todaySales } })
1001
1009
  }
1002
1010
  })
1011
+ setValues({})
1012
+ handleChange({ target: { name: 'tableId', value: '' } })
1003
1013
  getOnePedidoStore({
1004
1014
  variables: {
1005
1015
  pCodeRef: code || ''
@@ -345,6 +345,7 @@ export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
345
345
  $pCodeRef: String
346
346
  $discount: Int
347
347
  $change: Float
348
+ $tableId: ID
348
349
  $valueDelivery: Float
349
350
  $payMethodPState: Int
350
351
  $pickUp: Int
@@ -357,6 +358,7 @@ export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
357
358
  idStore: $idStore
358
359
  pCodeRef: $pCodeRef
359
360
  change: $change
361
+ tableId: $tableId
360
362
  discount: $discount
361
363
  valueDelivery: $valueDelivery
362
364
  payMethodPState: $payMethodPState
@@ -0,0 +1,2 @@
1
+ export * from './useStoreTableCreate'
2
+ export * from './useStoreTables'
@@ -0,0 +1,47 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ /**
4
+ * GraphQL Mutation for creating a store table
5
+ */
6
+ export const CREATE_TABLE_MUTATION = gql`
7
+ mutation storeTableCreate($tableName: String!, $seats: Int, $section: String, $tableState: Int) {
8
+ storeTableCreate(tableName: $tableName, seats: $seats, section: $section, tableState: $tableState) {
9
+ success
10
+ message
11
+ errors {
12
+ message
13
+ path
14
+ type
15
+ context {
16
+ limit
17
+ value
18
+ label
19
+ key
20
+ }
21
+ }
22
+ data {
23
+ tableId
24
+ tableName
25
+ seats
26
+ section
27
+ tableState
28
+ createdAt
29
+ updatedAt
30
+ }
31
+ }
32
+ }
33
+ `
34
+
35
+ export const STORE_TABLES_QUERY = gql`
36
+ query {
37
+ storeTables {
38
+ tableId
39
+ tableName
40
+ seats
41
+ section
42
+ tableState
43
+ createdAt
44
+ updatedAt
45
+ }
46
+ }
47
+ `
@@ -0,0 +1,76 @@
1
+ import { useState } from 'react'
2
+ import { gql, useMutation } from '@apollo/client'
3
+ import { CREATE_TABLE_MUTATION } from './queries'
4
+
5
+ /**
6
+ * Custom hook to handle table creation with validation and mutation logic
7
+ * @param {string} tableName Name of the table
8
+ * @param {number} seats Number of seats at the table
9
+ * @param {string} section Section where the table is located
10
+ * @param {number} tableState Current state of the table (e.g., Active, Occupied)
11
+ * @returns {Object} The state of the mutation including success, message, errors, and data
12
+ */
13
+ export const useStoreTableCreate = ({
14
+ sendNotification = () => {}
15
+ } = {}) => {
16
+ const [loading, setLoading] = useState(false)
17
+ const [createTableMutation] = useMutation(CREATE_TABLE_MUTATION)
18
+ /**
19
+ * Function to create a table with validation and mutation
20
+ * @param {string} tableName Table name
21
+ * @param {number} seats Number of seats
22
+ * @param {string} section Table section
23
+ * @param {number} tableState Table state (e.g., 0 = Unavailable, 1 = Active, 2 = Occupied)
24
+ */
25
+ const storeTableCreate = async (tableName, seats, section, tableState) => {
26
+ setLoading(true) // Start loading
27
+ try {
28
+ // Call the mutation to create the table
29
+ const result = await createTableMutation({
30
+ variables: {
31
+ tableName,
32
+ seats,
33
+ section,
34
+ tableState
35
+ },
36
+ update (cache, { data: { storeTableCreate } }) {
37
+ if (storeTableCreate.success) {
38
+ // Actualizar la lista de mesas en la cachΓ©
39
+ cache.modify({
40
+ fields: {
41
+ storeTables (existingTables = []) {
42
+ const newTableRef = {
43
+ tableId: null,
44
+ tableName,
45
+ seats,
46
+ section,
47
+ tableState: 1
48
+ }
49
+ return [...existingTables, newTableRef]
50
+ }
51
+ }
52
+ })
53
+ }
54
+ }
55
+ })
56
+
57
+ sendNotification({
58
+ backgroundColor: result.data.storeTableCreate.success ? 'success' : 'error',
59
+ description: result.data.storeTableCreate.message || '',
60
+ title: result.data.storeTableCreate.success ? 'Success' : 'Error'
61
+ })
62
+ return result
63
+ } catch (error) {
64
+ sendNotification({
65
+ backgroundColor: 'error',
66
+ description: error.message || 'Error occurred while creating the table.',
67
+ title: 'Creation Failed'
68
+ })
69
+ return { success: false, message: error.message }
70
+ } finally {
71
+ setLoading(false)
72
+ }
73
+ }
74
+
75
+ return [storeTableCreate, { loading }]
76
+ }
@@ -0,0 +1,14 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { STORE_TABLES_QUERY } from './queries' // Ajusta la ruta a tu archivo de queries
3
+
4
+ /**
5
+ * Custom hook to fetch store tables data
6
+ * @param {Object} args - Arguments for fetching store tables, e.g., info field.
7
+ * @param {Object} ctx - Context that provides restaurant-related information.
8
+ * @returns {Object} - Object containing tables data, loading state, and error.
9
+ */
10
+ export const useStoreTables = () => {
11
+ const { data, loading, error } = useQuery(STORE_TABLES_QUERY)
12
+
13
+ return [data, { loading, error }]
14
+ }
@@ -21,7 +21,6 @@ export const useSubscriptionValidation = (idStore) => {
21
21
  const [daysElapsed, setDaysElapsed] = useState(null)
22
22
 
23
23
  useEffect(() => {
24
- console.log(data)
25
24
  if (data && data.validateFreeSubscription) {
26
25
  const { currentPeriodEnd, currentPeriodStart } = data.validateFreeSubscription
27
26
  const currentDate = new Date()
@@ -33,7 +33,7 @@ export const updateExistingOrders = (
33
33
  2: 'PROCESSING',
34
34
  3: 'READY',
35
35
  4: 'CONCLUDES',
36
- 5: 'RECHAZADOS'
36
+ 5: 'REJECTED'
37
37
  }
38
38
  const targetArray = statusKeys[pSState]
39
39
 
@@ -56,6 +56,7 @@ username
56
56
  lastName
57
57
  email
58
58
  avatar
59
+ idRole
59
60
  uToken
60
61
  uPhoNum
61
62
  ULocation
@@ -69,6 +70,12 @@ associateStore
69
70
  createAt
70
71
  role {
71
72
  name
73
+ idRole,
74
+ permissions
75
+ description
76
+ createdAt
77
+ updatedAt
78
+
72
79
  }
73
80
  }
74
81
  }
@@ -19,7 +19,7 @@ export const statusOrder = {
19
19
  2: 'PROCESO',
20
20
  3: 'LISTOS',
21
21
  4: 'CONCLUIDOS',
22
- 5: 'RECHAZADOS'
22
+ 5: 'REJECTED'
23
23
  }
24
24
 
25
25
  export const statusProduct = {
@@ -28,6 +28,9 @@ export const statusProduct = {
28
28
  }
29
29
 
30
30
  export const validationSubmitHooks = elements => {
31
+ if (!elements || elements.length === 0) {
32
+ return {}
33
+ }
31
34
  let errorForm = {}
32
35
 
33
36
  for (const element of elements) {