Envases de Cosecha (Harvest Storages)

Los envases de cosecha representan los contenedores fisicos donde se almacenan las cosechas procesadas. Esta API gestiona frascos, cajas, bolsas, bovedas y estanterias, permitiendo trackear el peso, humedad y ubicacion de cada contenedor.


El modelo de Envase

  • Name
    id
    Type
    string
    Description

    Identificador unico.

  • Name
    code
    Type
    string
    Description

    Codigo del envase (auto-generado o personalizado). Ej: JAR-0001.

  • Name
    name
    Type
    string
    Description

    Nombre descriptivo del envase.

  • Name
    type
    Type
    HarvestStorageType
    Description

    Tipo de contenedor.

  • Name
    status
    Type
    HarvestStorageStatus
    Description

    Estado actual del envase.

  • Name
    harvests
    Type
    Harvest[]
    Description

    Cosechas almacenadas (relacion N-N).

  • Name
    weight
    Type
    number
    Description

    Peso actual en gramos.

  • Name
    maxCapacity
    Type
    number
    Description

    Capacidad maxima en gramos.

  • Name
    humidity
    Type
    number
    Description

    Porcentaje de humedad (0-100).

  • Name
    location
    Type
    string
    Description

    Ubicacion fisica del envase.

  • Name
    sealedAt
    Type
    timestamp
    Description

    Fecha de sellado.

  • Name
    lastOpenedAt
    Type
    timestamp
    Description

    Ultima apertura.

  • Name
    notes
    Type
    string
    Description

    Notas adicionales.

  • Name
    createdAt
    Type
    timestamp
    Description

    Fecha de creacion.

  • Name
    updatedAt
    Type
    timestamp
    Description

    Ultima actualizacion.

Ejemplo de envase

{
  "id": "storage-001",
  "code": "JAR-0001",
  "name": "Blue Dream Lote 1 - Frasco A",
  "type": "JAR",
  "status": "ACTIVE",
  "harvests": [
    {
      "id": "harvest-001",
      "name": "Blue Dream Lote #1",
      "batchNumber": "BD-2024-001",
      "strain": { "id": "strain_blue_dream", "name": "Blue Dream" }
    }
  ],
  "weight": 28.5,
  "maxCapacity": 30,
  "humidity": 62,
  "location": "Bodega A - Estante 3",
  "sealedAt": null,
  "lastOpenedAt": "2024-10-15T14:30:00Z",
  "notes": "Curado optimo, tricomas intactos",
  "createdAt": "2024-10-01T00:00:00Z",
  "updatedAt": "2024-10-15T14:30:00Z"
}

Tipos de Envase (HarvestStorageType)

TipoLabelPrefijoDescripcion
JARFrascoJAR-Frascos de vidrio hermeticos para curado
BOXCajaBOX-Cajas de carton o madera
BAGBolsaBAG-Bolsas selladas al vacio o con cierre
VAULTBovedaVLT-Bovedas de curado con control de humedad
SHELFEstanteriaSHF-Estanterias o espacios abiertos

Estados de Envase (HarvestStorageStatus)

Loading diagram...
EstadoDescripcion
ACTIVEEn uso, se puede agregar o extraer contenido
FULLCapacidad maxima alcanzada
EMPTYSin contenido, disponible para reutilizar
SEALEDSellado para curado a largo plazo

GET/api/crops/harvest-storages

Listar envases

Parametros de Consulta

  • Name
    type
    Type
    HarvestStorageType
    Description

    Filtrar por tipo de envase.

  • Name
    status
    Type
    HarvestStorageStatus
    Description

    Filtrar por estado.

  • Name
    harvestId
    Type
    string
    Description

    Filtrar por cosecha almacenada.

  • Name
    search
    Type
    string
    Description

    Busqueda por codigo o nombre.

Request

GET
/api/crops/harvest-storages
curl -G https://api.cannahub.tech/api/crops/harvest-storages \
  -H "Authorization: Bearer {token}" \
  -d type=JAR \
  -d status=ACTIVE

Response

{
  "harvestStorages": [...],
  "count": 8
}

POST/api/crops/harvest-storages

Crear envase

Crea un nuevo envase de cosecha. El codigo se genera automaticamente con el prefijo del tipo si no se proporciona.

Campos Requeridos

  • Name
    type
    Type
    HarvestStorageType
    Description

    Tipo de envase.

  • Name
    weight
    Type
    number
    Description

    Peso inicial en gramos.

Campos Opcionales

  • Name
    code
    Type
    string
    Description

    Codigo personalizado (si no se proporciona, se auto-genera).

  • Name
    name
    Type
    string
    Description

    Nombre descriptivo.

  • Name
    harvestIds
    Type
    string[]
    Description

    IDs de cosechas a vincular.

  • Name
    maxCapacity
    Type
    number
    Description

    Capacidad maxima en gramos.

  • Name
    humidity
    Type
    number
    Description

    Humedad inicial (0-100).

  • Name
    location
    Type
    string
    Description

    Ubicacion fisica.

  • Name
    notes
    Type
    string
    Description

    Notas adicionales.

Request

POST
/api/crops/harvest-storages
curl -X POST https://api.cannahub.tech/api/crops/harvest-storages \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "JAR",
    "weight": 28.5,
    "maxCapacity": 30,
    "humidity": 62,
    "harvestIds": ["harvest-001"],
    "location": "Bodega A - Estante 3"
  }'

Response (201)

{
  "harvestStorage": {
    "id": "storage-1698765432100",
    "code": "JAR-0001",
    "type": "JAR",
    "status": "ACTIVE",
    "weight": 28.5,
    "maxCapacity": 30,
    "humidity": 62,
    "location": "Bodega A - Estante 3",
    "harvests": [...]
  }
}

GET/api/crops/harvest-storages/:id

Obtener envase

Retorna los detalles de un envase especifico.

Request

curl https://api.cannahub.tech/api/crops/harvest-storages/storage-001 \
  -H "Authorization: Bearer {token}"

PATCH/api/crops/harvest-storages/:id

Actualizar envase

Actualiza datos del envase. El estado se recalcula automaticamente basado en el peso y capacidad maxima.

Campos Actualizables

  • Name
    code
    Type
    string
    Description

    Codigo del envase.

  • Name
    name
    Type
    string
    Description

    Nombre descriptivo.

  • Name
    type
    Type
    HarvestStorageType
    Description

    Tipo de envase.

  • Name
    status
    Type
    HarvestStorageStatus
    Description

    Estado manual (SEALED requiere seteo explicito).

  • Name
    harvestIds
    Type
    string[]
    Description

    IDs de cosechas vinculadas.

  • Name
    weight
    Type
    number
    Description

    Peso actual (recalcula estado).

  • Name
    maxCapacity
    Type
    number
    Description

    Capacidad maxima.

  • Name
    humidity
    Type
    number
    Description

    Humedad actual.

  • Name
    location
    Type
    string
    Description

    Ubicacion fisica.

  • Name
    notes
    Type
    string
    Description

    Notas adicionales.

Request

PATCH
/api/crops/harvest-storages/:id
curl -X PATCH https://api.cannahub.tech/api/crops/harvest-storages/storage-001 \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "weight": 15.2,
    "humidity": 60,
    "notes": "Extraidos 13.3g para venta"
  }'

DELETE/api/crops/harvest-storages/:id

Eliminar envase

Elimina un envase del sistema.

Request

curl -X DELETE https://api.cannahub.tech/api/crops/harvest-storages/storage-001 \
  -H "Authorization: Bearer {token}"

Generacion Automatica de Codigos

Los codigos se generan automaticamente con el prefijo del tipo:

TipoPrefijoEjemplo
JARJAR-JAR-0001, JAR-0002
BOXBOX-BOX-0001, BOX-0002
BAGBAG-BAG-0001, BAG-0002
VAULTVLT-VLT-0001, VLT-0002
SHELFSHF-SHF-0001, SHF-0002

El numero se incrementa automaticamente basado en el ultimo codigo existente del mismo tipo.


React Query Hooks

Uso de hooks

import {
  useHarvestStoragesQuery,
  useHarvestStorageQuery,
  useCreateHarvestStorageMutation,
  useUpdateHarvestStorageMutation,
  useDeleteHarvestStorageMutation
} from '@/features/Club/Crops/HarvestStorages/hooks'

// Listar envases con filtros
const { data: storages, isLoading } = useHarvestStoragesQuery({
  type: 'JAR',
  status: 'ACTIVE'
})

// Obtener un envase
const { data: storage } = useHarvestStorageQuery('storage-001')

// Crear envase
const createMutation = useCreateHarvestStorageMutation()
await createMutation.mutateAsync({
  type: 'JAR',
  weight: 28.5,
  maxCapacity: 30,
  humidity: 62,
  harvestIds: ['harvest-001'],
  location: 'Bodega A - Estante 3'
})

// Actualizar envase
const updateMutation = useUpdateHarvestStorageMutation()
await updateMutation.mutateAsync({
  id: 'storage-001',
  data: { weight: 15.2, notes: 'Extraidos 13.3g' }
})

// Eliminar envase
const deleteMutation = useDeleteHarvestStorageMutation()
await deleteMutation.mutateAsync('storage-001')

Query Keys

harvestStorageKeys = {
  all: ['harvestStorages'],
  lists: () => ['harvestStorages', 'list'],
  list: (filters) => ['harvestStorages', 'list', filters],
  details: () => ['harvestStorages', 'detail'],
  detail: (id) => ['harvestStorages', 'detail', id]
}

Proximos Pasos

Was this page helpful?