Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/EricMartinez758/corpointa-frontend/llms.txt

Use this file to discover all available pages before exploring further.

Materials are the core items tracked by Corpointa’s inventory system. Each material record captures a human-readable description, its classification category, the unit of measure used to count it, and an optional physical storage location. The module is accessible at the /materiales route and provides a full-featured data table with search, filters, and inline dialogs for creating, editing, and deleting records.

Data Model

The Material type is derived from the Zod schema defined in src/features/materiales/data/schema.ts.
export const materialSchema = z.object({
  id_material:       z.number(),
  descripcion:       z.string().min(1, { message: 'La descripción es requerida' }).max(50),
  fk_id_categoria:   z.number({ required_error: 'La categoría es requerida' }),
  fk_id_medida:      z.number({ required_error: 'La unidad de medida es requerida' }),
  ubicacion:         z.string().max(30).optional().nullable(),
  fk_id_usuario_crea:    z.number().optional(),
  fecha_creacion:        z.string().optional(),
  fecha_actualizacion:   z.string().nullable().optional(),
  // Read-only JOIN fields
  categoria_nombre:  z.string().optional(),
  medida_nombre:     z.string().optional(),
})

export type Material = z.infer<typeof materialSchema>

Field Reference

FieldTypeConstraintsDescription
id_materialnumberAuto-assignedPrimary key.
descripcionstringRequired, max 50 charsHuman-readable name of the material.
fk_id_categorianumberRequiredForeign key to the categorias table.
fk_id_medidanumberRequiredForeign key to the unidades-medidas table.
ubicacionstring | nullOptional, max 30 charsPhysical storage location (shelf, bin, room, etc.).
fk_id_usuario_creanumberRead-onlyID of the user who created the record.
fecha_creacionstringRead-onlyISO timestamp of record creation.
fecha_actualizacionstring | nullRead-onlyISO timestamp of last update.
categoria_nombrestringRead-only JOINHuman-readable category name — populated by the API via JOIN, never sent on write.
medida_nombrestringRead-only JOINHuman-readable unit name — populated by the API via JOIN, never sent on write.
categoria_nombre and medida_nombre are resolved by the backend through a SQL JOIN and are included in GET responses for display purposes. Do not include them in POST or PUT request bodies — they will be ignored or may cause validation errors.

Features

Searchable Data Table

The materials table supports column-level search and global filtering. Results update as you type, allowing quick lookup by description, category, or location.

Create Dialog

A modal form lets users enter a description, choose a category and unit of measure from dropdowns, and optionally specify a storage location. Client-side Zod validation runs before submission.

Edit Dialog

Clicking the edit action on any row opens the same form pre-populated with the material’s current values. Only the writable fields are sent to the API on save.

Delete Dialog

A confirmation dialog prevents accidental deletions. The record is removed via DELETE /materiales/:id.

API Operations

All functions live in src/features/materiales/api/materiales.ts and use the shared apiClient (Axios instance with base URL and auth headers).
MethodEndpointFunctionDescription
GET/materialesgetMateriales()Returns all material records, each including categoria_nombre and medida_nombre via JOIN.
GET/materiales/:idgetMaterial(id)Returns a single material by its id_material.
POST/materialescreateMaterial(data)Creates a new material. Body must include descripcion, fk_id_categoria, and fk_id_medida.
PUT/materiales/:idupdateMaterial(id, data)Updates an existing material. Same writable fields as POST.
DELETE/materiales/:iddeleteMaterial(id)Permanently removes a material record.

Create / Update Payload

For both POST and PUT, send only the writable fields. The id_material, categoria_nombre, medida_nombre, fk_id_usuario_crea, fecha_creacion, and fecha_actualizacion fields are excluded from the payload type:
type MaterialPayload = Omit<
  Material,
  | 'id_material'
  | 'categoria_nombre'
  | 'medida_nombre'
  | 'fk_id_usuario_crea'
  | 'fecha_creacion'
  | 'fecha_actualizacion'
>

Example: Create a Material

import { createMaterial } from '@/features/materiales/api/materiales'

const newMaterial = await createMaterial({
  descripcion:     'Cable UTP Cat6 (rollo 100m)',
  fk_id_categoria: 3,
  fk_id_medida:    1,
  ubicacion:       'Estante A-12',
})

Example: GET Response

[
  {
    "id_material": 7,
    "descripcion": "Cable UTP Cat6 (rollo 100m)",
    "fk_id_categoria": 3,
    "fk_id_medida": 1,
    "ubicacion": "Estante A-12",
    "fk_id_usuario_crea": 1,
    "fecha_creacion": "2025-05-10T08:30:00.000Z",
    "fecha_actualizacion": null,
    "categoria_nombre": "Eléctrico",
    "medida_nombre": "Unidad"
  }
]
Deleting a material that has existing stock records (existencias) or movement history may be blocked by the backend with a foreign-key constraint error. Resolve associated records first before attempting deletion.

Build docs developers (and LLMs) love