Se pudo conectar satisfactoriamente a la base de datos tenantdb_1 y suitecoffee-db.
En ./services/app/ Se sirvierons los HTML de la carpeta /pages. Se crearon los endpoints REST para crear y listar roles, usuarios, categorias, productos.
This commit is contained in:
parent
656293b74c
commit
f483058c2c
110
README.md
110
README.md
@ -1,110 +0,0 @@
|
||||
|
||||
# Proyecto Node.js con Docker
|
||||
|
||||
Este proyecto es una aplicación Node.js containerizada usando Docker y Docker Compose, con entornos separados para desarrollo y producción. A continuación, se explica cómo configurar y ejecutar la aplicación en ambos entornos.
|
||||
|
||||
## Estructura del Proyecto
|
||||
|
||||
```
|
||||
.
|
||||
├── Dockerfile.dev # Dockerfile para entorno de desarrollo
|
||||
├── Dockerfile.prod # Dockerfile para entorno de producción
|
||||
├── docker-compose.dev.yml # Archivo de configuración para entorno de desarrollo
|
||||
├── docker-compose.prod.yml # Archivo de configuración para entorno de producción
|
||||
├── package.json # Dependencias del proyecto Node.js
|
||||
├── src/ # Código fuente de la aplicación
|
||||
└── ...
|
||||
```
|
||||
|
||||
## Prerequisitos
|
||||
|
||||
Antes de comenzar, asegúrate de tener instalado:
|
||||
|
||||
- [Docker](https://www.docker.com/get-started)
|
||||
- [Docker Compose](https://docs.docker.com/compose/install/)
|
||||
|
||||
## Configuración
|
||||
|
||||
### 1. Instalar dependencias
|
||||
|
||||
Primero, asegúrate de tener todas las dependencias necesarias para tu proyecto. Si aún no tienes el archivo `package.json`, ejecuta:
|
||||
|
||||
```bash
|
||||
npm init -y
|
||||
```
|
||||
|
||||
Luego, instala las dependencias necesarias para tu aplicación:
|
||||
|
||||
```bash
|
||||
npm install express
|
||||
npm install --save-dev nodemon
|
||||
```
|
||||
|
||||
### 2. Estructura de los Dockerfiles
|
||||
|
||||
- **`Dockerfile.dev`**: Configuración para el entorno de desarrollo.
|
||||
- **`Dockerfile.prod`**: Configuración para el entorno de producción.
|
||||
|
||||
### 3. Configuración de Docker Compose
|
||||
|
||||
- **`docker-compose.dev.yml`**: Configuración para el entorno de desarrollo. Utiliza `nodemon` para recargar la aplicación automáticamente.
|
||||
- **`docker-compose.prod.yml`**: Configuración para el entorno de producción. Instala solo las dependencias necesarias para producción.
|
||||
|
||||
## Uso
|
||||
|
||||
### 1. Entorno de Desarrollo
|
||||
|
||||
Para levantar el entorno de desarrollo y comenzar a trabajar, ejecuta:
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose.dev.yml up --build
|
||||
```
|
||||
|
||||
Esto hará lo siguiente:
|
||||
- Construirá la imagen usando el `Dockerfile.dev`.
|
||||
- Levantará el contenedor en el puerto `3000`.
|
||||
- Con `nodemon` instalado, cualquier cambio que realices en el código será automáticamente reflejado en el contenedor.
|
||||
|
||||
Puedes acceder a la aplicación en tu navegador en `http://localhost:3000`.
|
||||
|
||||
### 2. Entorno de Producción
|
||||
|
||||
Para ejecutar el entorno de producción (sin dependencias de desarrollo), ejecuta:
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose.prod.yml up --build
|
||||
```
|
||||
|
||||
Esto:
|
||||
- Construirá la imagen usando el `Dockerfile.prod`.
|
||||
- Levantará el contenedor en el puerto `3000`.
|
||||
|
||||
En este entorno no se instalarán dependencias de desarrollo y es más ligero para producción.
|
||||
|
||||
### 3. Detener los contenedores
|
||||
|
||||
Si necesitas detener los contenedores en ejecución, puedes usar:
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
```
|
||||
|
||||
Para eliminar también las imágenes, ejecuta:
|
||||
|
||||
```bash
|
||||
docker compose down --rmi all
|
||||
```
|
||||
|
||||
## Notas adicionales
|
||||
|
||||
- Si necesitas acceder al contenedor para depurar o inspeccionar archivos, puedes hacerlo con el siguiente comando:
|
||||
|
||||
```bash
|
||||
docker exec -it <container_id> sh
|
||||
```
|
||||
|
||||
- Si tienes alguna duda o problema, no dudes en contactarnos o abrir un issue en el repositorio.
|
||||
|
||||
---
|
||||
|
||||
¡Disfruta trabajando con tu aplicación Node.js containerizada!
|
||||
195
backup/comandas.html
Normal file
195
backup/comandas.html
Normal file
@ -0,0 +1,195 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Crear comanda</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Crear comanda</h1>
|
||||
|
||||
<section>
|
||||
<label>
|
||||
Mesa (ID o número):
|
||||
<input type="number" id="mesaId" required />
|
||||
</label>
|
||||
<br />
|
||||
<label>
|
||||
Mozo (ID de usuario):
|
||||
<input type="text" id="mozoId" required />
|
||||
</label>
|
||||
<br />
|
||||
<label>
|
||||
Notas:
|
||||
<input type="text" id="notas" placeholder="Sin observaciones" />
|
||||
</label>
|
||||
</section>
|
||||
|
||||
<hr />
|
||||
|
||||
<section>
|
||||
<h2>Agregar productos</h2>
|
||||
<label>
|
||||
Producto:
|
||||
<select id="productoSelect"></select>
|
||||
</label>
|
||||
<label>
|
||||
Cantidad:
|
||||
<input type="number" id="cantidadInput" value="1" min="1" />
|
||||
</label>
|
||||
<button id="agregarBtn">Agregar</button>
|
||||
|
||||
<h3>Items de la comanda</h3>
|
||||
<ul id="itemsList"></ul>
|
||||
</section>
|
||||
|
||||
<hr />
|
||||
|
||||
<button id="enviarBtn">Enviar comanda</button>
|
||||
<pre id="salida"></pre>
|
||||
|
||||
<script>
|
||||
// === CONFIGURA AQUÍ SI ES NECESARIO ===
|
||||
const API_BASE = "http://localhost:3000"; // Cambia al puerto/host de tu servidor Node
|
||||
const PRODUCTOS_PATH = "/productos"; // GET
|
||||
const COMANDAS_PATH = "/comandas"; // POST
|
||||
|
||||
// === ESTADO EN MEMORIA ===
|
||||
const productosCache = new Map(); // id -> {id, nombre, ...}
|
||||
const items = []; // {producto_id, cantidad}
|
||||
|
||||
// === ELEMENTOS DEL DOM ===
|
||||
const productoSelect = document.getElementById("productoSelect");
|
||||
const cantidadInput = document.getElementById("cantidadInput");
|
||||
const agregarBtn = document.getElementById("agregarBtn");
|
||||
const itemsList = document.getElementById("itemsList");
|
||||
const enviarBtn = document.getElementById("enviarBtn");
|
||||
const mesaIdInput = document.getElementById("mesaId");
|
||||
const mozoIdInput = document.getElementById("mozoId");
|
||||
const notasInput = document.getElementById("notas");
|
||||
const salida = document.getElementById("salida");
|
||||
|
||||
// === UTILIDADES ===
|
||||
function renderItems() {
|
||||
itemsList.innerHTML = "";
|
||||
items.forEach((it, idx) => {
|
||||
const li = document.createElement("li");
|
||||
const prod = productosCache.get(it.producto_id);
|
||||
const nombre = prod ? (prod.nombre || prod.name || `Producto ${it.producto_id}`) : `ID ${it.producto_id}`;
|
||||
li.textContent = `${nombre} × ${it.cantidad}`;
|
||||
const btn = document.createElement("button");
|
||||
btn.textContent = "Quitar";
|
||||
btn.onclick = () => {
|
||||
items.splice(idx, 1);
|
||||
renderItems();
|
||||
};
|
||||
li.appendChild(document.createTextNode(" "));
|
||||
li.appendChild(btn);
|
||||
itemsList.appendChild(li);
|
||||
});
|
||||
}
|
||||
|
||||
function mostrarMensaje(obj) {
|
||||
try {
|
||||
salida.textContent = typeof obj === "string" ? obj : JSON.stringify(obj, null, 2);
|
||||
} catch {
|
||||
salida.textContent = String(obj);
|
||||
}
|
||||
}
|
||||
|
||||
function validarEnteroPositivo(valor) {
|
||||
const n = Number(valor);
|
||||
return Number.isInteger(n) && n > 0;
|
||||
}
|
||||
|
||||
// === LOGICA ===
|
||||
async function cargarProductos() {
|
||||
try {
|
||||
const res = await fetch(API_BASE + PRODUCTOS_PATH);
|
||||
if (!res.ok) throw new Error("No se pudieron obtener los productos");
|
||||
const data = await res.json();
|
||||
// Espera un array de productos con al menos {id, nombre}
|
||||
productoSelect.innerHTML = "";
|
||||
data.forEach(p => {
|
||||
productosCache.set(p.id, p);
|
||||
const opt = document.createElement("option");
|
||||
opt.value = p.id;
|
||||
opt.textContent = p.nombre || p.name || `Producto ${p.id}`;
|
||||
productoSelect.appendChild(opt);
|
||||
});
|
||||
if (data.length === 0) {
|
||||
mostrarMensaje("No hay productos disponibles.");
|
||||
}
|
||||
} catch (e) {
|
||||
mostrarMensaje("Error cargando productos: " + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
agregarBtn.addEventListener("click", () => {
|
||||
const prodId = Number(productoSelect.value);
|
||||
const cant = Number(cantidadInput.value);
|
||||
if (!validarEnteroPositivo(prodId)) {
|
||||
return mostrarMensaje("Selecciona un producto válido.");
|
||||
}
|
||||
if (!validarEnteroPositivo(cant)) {
|
||||
return mostrarMensaje("La cantidad debe ser un entero positivo.");
|
||||
}
|
||||
// Si ya existe el producto en la lista, acumula cantidad
|
||||
const existente = items.find(i => i.producto_id === prodId);
|
||||
if (existente) {
|
||||
existente.cantidad += cant;
|
||||
} else {
|
||||
items.push({ producto_id: prodId, cantidad: cant });
|
||||
}
|
||||
renderItems();
|
||||
cantidadInput.value = 1;
|
||||
mostrarMensaje("Producto agregado.");
|
||||
});
|
||||
|
||||
enviarBtn.addEventListener("click", async () => {
|
||||
const mesa_id = Number(mesaIdInput.value);
|
||||
const mozo_id = mozoIdInput.value.trim();
|
||||
const notas = notasInput.value.trim();
|
||||
|
||||
if (!validarEnteroPositivo(mesa_id)) {
|
||||
return mostrarMensaje("Debes indicar un número de mesa válido.");
|
||||
}
|
||||
if (!mozo_id) {
|
||||
return mostrarMensaje("Debes indicar el ID del mozo.");
|
||||
}
|
||||
if (items.length === 0) {
|
||||
return mostrarMensaje("Agrega al menos un producto a la comanda.");
|
||||
}
|
||||
|
||||
const payload = { mesa_id, mozo_id, notas, items };
|
||||
|
||||
enviarBtn.disabled = true;
|
||||
mostrarMensaje("Enviando comanda...");
|
||||
|
||||
try {
|
||||
const res = await fetch(API_BASE + COMANDAS_PATH, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
mostrarMensaje({ error: "No se pudo crear la comanda", detalle: data });
|
||||
} else {
|
||||
mostrarMensaje({ ok: true, comanda: data });
|
||||
// Limpia el estado
|
||||
items.length = 0;
|
||||
renderItems();
|
||||
notasInput.value = "";
|
||||
}
|
||||
} catch (e) {
|
||||
mostrarMensaje("Error al enviar comanda: " + e.message);
|
||||
} finally {
|
||||
enviarBtn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// Cargar productos al iniciar
|
||||
cargarProductos();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,73 +0,0 @@
|
||||
-- Crear la base de datos solo si no existe
|
||||
CREATE DATABASE IF NOT EXISTS `suitecoffee`;
|
||||
|
||||
USE `suitecoffee`;
|
||||
|
||||
-- Crear tabla de categorías
|
||||
CREATE TABLE IF NOT EXISTS categorias (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
nombre VARCHAR(100) NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
-- Crear tabla de productos
|
||||
CREATE TABLE IF NOT EXISTS productos (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
nombre VARCHAR(100) NOT NULL,
|
||||
precio DECIMAL(10,2) NOT NULL,
|
||||
categoria_id INT,
|
||||
FOREIGN KEY (categoria_id) REFERENCES categorias(id)
|
||||
);
|
||||
|
||||
-- Crear tabla de mesas
|
||||
CREATE TABLE IF NOT EXISTS mesas (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
numero INT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
-- Crear tabla de comandas con productos en JSON
|
||||
CREATE TABLE IF NOT EXISTS comandas (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
mesa_id INT NOT NULL,
|
||||
productos JSON NOT NULL, -- Array de productos con cantidad y precio
|
||||
fecha DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
total DECIMAL(10,2),
|
||||
FOREIGN KEY (mesa_id) REFERENCES mesas(id)
|
||||
);
|
||||
|
||||
-- Insertar categoría 'Café' en la tabla categorias
|
||||
INSERT INTO categorias (nombre) VALUES ('cafe');
|
||||
|
||||
-- Insertar mesa '1, 2 y 3' en la tabla mesas
|
||||
INSERT INTO mesas (numero)
|
||||
VALUES
|
||||
(1),
|
||||
(2),
|
||||
(3);
|
||||
|
||||
-- Insertar cappuccino en la tabla productos, asociándolo con la categoría 'Café'
|
||||
INSERT INTO productos (nombre, precio, categoria_id)
|
||||
VALUES
|
||||
('Cappuccino', 200.00, (SELECT id FROM categorias WHERE nombre = 'Café')),
|
||||
('Latte', 200.00, (SELECT id FROM categorias WHERE nombre = 'Café')),
|
||||
('Espresso', 120.00, (SELECT id FROM categorias WHERE nombre = 'Café'));
|
||||
('Frappe', 290.00, (SELECT id FROM categorias WHERE nombre = 'Café'));
|
||||
|
||||
-- Insertar una comanda en la tabla comandas para la mesa 1
|
||||
INSERT INTO comandas (mesa_id, productos, total)
|
||||
VALUES
|
||||
(
|
||||
2, -- mesa_id
|
||||
JSON_ARRAY(
|
||||
JSON_OBJECT('producto_id', (SELECT id FROM productos WHERE nombre = 'Expresso'), 'cantidad', 2, 'precio_unitario', 111.00),
|
||||
JSON_OBJECT('producto_id', (SELECT id FROM productos WHERE nombre = 'Latte'), 'cantidad', 1, 'precio_unitario', 666.00)
|
||||
),
|
||||
208457935.00 -- total (2 Cappuccinos * 200 + 1 Latte * 220)
|
||||
),
|
||||
(
|
||||
3, -- mesa_id
|
||||
JSON_ARRAY(
|
||||
JSON_OBJECT('producto_id', (SELECT id FROM productos WHERE nombre = 'Cappuccino'), 'cantidad', 2, 'precio_unitario', 444.00),
|
||||
JSON_OBJECT('producto_id', (SELECT id FROM productos WHERE nombre = 'Frappe'), 'cantidad', 4, 'precio_unitario', 222.00)
|
||||
),
|
||||
93826.00 -- total (2 Cappuccinos * 200 + 1 Latte * 220)
|
||||
);
|
||||
80
docker-compose.override.yml
Normal file
80
docker-compose.override.yml
Normal file
@ -0,0 +1,80 @@
|
||||
# docker-compose.overrride.yml
|
||||
# Docker Comose para entorno de desarrollo o development.
|
||||
|
||||
# <---- Estructura ---->
|
||||
# services:
|
||||
# suitecoffe-app
|
||||
# suitecoffe-db
|
||||
# auth-service (No implementado aún)
|
||||
# auth-db (No implementado aún)
|
||||
# volumes:
|
||||
# pg-appdb-data:
|
||||
# pg-authdb-data: (No implementado aún)
|
||||
|
||||
|
||||
services:
|
||||
|
||||
suitecoffee-app:
|
||||
container_name: suitecoffee-app
|
||||
depends_on:
|
||||
- suitecoffee-db
|
||||
build:
|
||||
context: ./services/app
|
||||
dockerfile: Dockerfile.development
|
||||
volumes:
|
||||
- ./services/app:/app
|
||||
ports:
|
||||
- ${APP_LOCAL_PORT}:${APP_DOCKER_PORT}
|
||||
env_file:
|
||||
- ./services/app/.env.development
|
||||
environment:
|
||||
- NODE_ENV=${NODE_ENV}
|
||||
command: npm run dev
|
||||
restart: unless-stopped
|
||||
|
||||
suitecoffee-db:
|
||||
image: postgres:16
|
||||
container_name: suitecoffee-db
|
||||
environment:
|
||||
POSTGRES_DB: suitecoffee
|
||||
POSTGRES_USER: suitecoffee
|
||||
POSTGRES_PASSWORD: suitecoffee
|
||||
ports:
|
||||
- "54321:5432"
|
||||
volumes:
|
||||
- pg-appdb-data:/var/lib/postgresql/data
|
||||
restart: unless-stopped
|
||||
|
||||
# auth-service:
|
||||
# container_name: auth-service
|
||||
# depends_on:
|
||||
# - auth-db
|
||||
# build:
|
||||
# context: ./services/app
|
||||
# dockerfile: Dockerfile.dev
|
||||
# volumes:
|
||||
# - ./services/auth:/app
|
||||
# ports:
|
||||
# - 3030:3030 # Usa la variable de entorno PORT
|
||||
# # env_file:
|
||||
# # - ./services/auth/.env.dev
|
||||
# environment:
|
||||
# # - NODE_ENV=dev
|
||||
# - PORT=3030
|
||||
# command: npm run dev # Usa nodemon para desarrollo (visitar package.json)
|
||||
# restart: unless-stopped
|
||||
|
||||
# auth-db:
|
||||
# container_name: auth-db
|
||||
# image: postgres:16
|
||||
# # ports:
|
||||
# # - ${AUTH_DB_LOCAL_PORT}:${AUTH_DB_DOCKER_PORT}
|
||||
# # env_file:
|
||||
# # - ./services/auth/.env.dev
|
||||
# environment:
|
||||
# POSTGRES_DB: "auth"
|
||||
# POSTGRES_USER: "dev_user"
|
||||
# POSTGRES_PASSWORD: "dev_password"
|
||||
|
||||
volumes:
|
||||
pg-appdb-data:
|
||||
@ -1,34 +0,0 @@
|
||||
# docker-compose.dev.yml
|
||||
|
||||
services:
|
||||
suitecoffee-app:
|
||||
container_name: suitecoffee-app
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.dev
|
||||
volumes:
|
||||
- .:/app
|
||||
ports:
|
||||
- "${PORT}:${PORT}" # Usa la variable de entorno PORT
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- PORT=${PORT}
|
||||
command: npm run dev # Usa nodemon para desarrollo
|
||||
restart: unless-stopped
|
||||
|
||||
suitecoffee-db:
|
||||
container_name: suitecoffee-db
|
||||
image: mysql:latest
|
||||
env_file:
|
||||
- .env.${NODE_ENV}
|
||||
environment:
|
||||
MYSQL_USER: $DB_USER
|
||||
MYSQL_PASSWORD: $DB_PASS
|
||||
MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
|
||||
MYSQL_DATABASE: $DB_NAME
|
||||
volumes:
|
||||
- ./db/dev-db:/var/lib/mysql
|
||||
- ./db/init:/docker-entrypoint-initdb.d
|
||||
ports:
|
||||
- "$DB_LOCAL_PORT:$DB_DOCKER_PORT"
|
||||
restart: unless-stopped
|
||||
@ -1,32 +0,0 @@
|
||||
# docker-compose.prod.yml
|
||||
|
||||
services:
|
||||
suitecoffee-app:
|
||||
container_name: suitecoffee-app
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.prod
|
||||
ports:
|
||||
- "${PORT}:${PORT}" # Usa la variable de entorno PORT
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=${PORT}
|
||||
command: npm start # Usa el comando de inicio en producción
|
||||
restart: unless-stopped
|
||||
|
||||
suitecoffee-db:
|
||||
container_name: suitecoffee-db
|
||||
image: mysql:latest
|
||||
env_file:
|
||||
- .env.${NODE_ENV}
|
||||
environment:
|
||||
MYSQL_USER: $DB_USER
|
||||
MYSQL_PASSWORD: $DB_PASS
|
||||
MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
|
||||
MYSQL_DATABASE: $DB_NAME
|
||||
volumes:
|
||||
- ./db/app-db/mysql_prod:/var/lib/mysql
|
||||
- ./db/init:/docker-entrypoint-initdb.d
|
||||
ports:
|
||||
- "$DB_LOCAL_PORT:$DB_DOCKER_PORT"
|
||||
restart: unless-stopped
|
||||
6
docs/Modelo Entidad-Relación.puml
Normal file
6
docs/Modelo Entidad-Relación.puml
Normal file
@ -0,0 +1,6 @@
|
||||
@startuml Modelo Entidad-Relacion
|
||||
class Producto {
|
||||
- idProducto: int
|
||||
+ getId(): int
|
||||
}
|
||||
@enduml
|
||||
2
myREADME.md
Normal file
2
myREADME.md
Normal file
@ -0,0 +1,2 @@
|
||||
docker compose -f docker-compose.yml -f docker-compose.override.yml \
|
||||
--env-file .env.development up -d
|
||||
23
package.json
23
package.json
@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "suitecoffee",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"dev": "nodemon index.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"type": "commonjs",
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.5.0",
|
||||
"express": "^5.1.0",
|
||||
"mysql2": "^3.14.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.1.9"
|
||||
}
|
||||
}
|
||||
250
server/index.js
250
server/index.js
@ -1,250 +0,0 @@
|
||||
// index.js
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const dotenv = require('dotenv');
|
||||
const mysql = require('mysql2/promise');
|
||||
const cors = require('cors');
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
// Cargar las variables de entorno dependiendo del entorno
|
||||
const envFile = process.env.NODE_ENV === 'production' ? '.env.production' : '.env.development';
|
||||
dotenv.config({ path: envFile });
|
||||
|
||||
// Configuración de conexión MySQL
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST || 'db',
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_DOCKER_PORT || 3306
|
||||
};
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
|
||||
// Servir archivos estáticos de la carpeta 'src'
|
||||
app.use(express.static(path.join(__dirname, 'src')));
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
// --------------------------------- RENDERIZADO --------------------------------------
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
// Ruta principal
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'src', 'index.html'));
|
||||
});
|
||||
|
||||
// Ruta para comandas
|
||||
app.get('/comandas', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'src', 'pages', 'comandas.html'));
|
||||
});
|
||||
// Ruta para dashboard
|
||||
app.get('/lectura', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'src', 'pages', 'lectura.html'));
|
||||
});
|
||||
// Ruta para dashboard
|
||||
app.get('/carga', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'src', 'pages', 'carga.html'));
|
||||
});
|
||||
|
||||
// Ruta para obtener las tablas de la base de datos
|
||||
app.get('/tablas', async (req, res) => {
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
const [rows] = await connection.execute(
|
||||
`SHOW TABLES FROM \`${dbConfig.database}\``
|
||||
);
|
||||
const tablas = rows.map(row => Object.values(row)[0]);
|
||||
res.json({ tablas });
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error al conectar o consultar la base de datos:', error);
|
||||
res.status(500).json({ error: 'Error interno al consultar la base de datos' });
|
||||
|
||||
} finally {
|
||||
if (connection) {
|
||||
await connection.end();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
// ----------------------------------- LECTURAS ---------------------------------------
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Obtener mesas
|
||||
app.get('/api/obtenerMesas', async (req, res) => {
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
const [results] = await connection.query('SELECT * FROM mesas');
|
||||
res.json(results);
|
||||
} catch (error) {
|
||||
console.error('Error al obtener mesas:', error);
|
||||
res.status(500).json({ error: 'Error al obtener mesas' });
|
||||
} finally {
|
||||
if (connection) await connection.end();
|
||||
}
|
||||
});
|
||||
|
||||
// Obtener productos
|
||||
app.get('/api/obtenerProductos', async (req, res) => {
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
const [results] = await connection.query('SELECT * FROM productos');
|
||||
res.json(results);
|
||||
} catch (error) {
|
||||
console.error('Error al obtener productos:', error);
|
||||
res.status(500).json({ error: 'Error al obtener productos' });
|
||||
} finally {
|
||||
if (connection) await connection.end();
|
||||
}
|
||||
});
|
||||
|
||||
// Obtener categorías
|
||||
app.get('/api/obtenerCategorias', async (req, res) => {
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
const [results] = await connection.query('SELECT * FROM categorias');
|
||||
res.json(results);
|
||||
} catch (error) {
|
||||
console.error('Error al obtener categorías:', error);
|
||||
res.status(500).json({ error: 'Error al obtener categorías' });
|
||||
} finally {
|
||||
if (connection) await connection.end();
|
||||
}
|
||||
});
|
||||
|
||||
// Obtener comandas
|
||||
app.get('/api/obtenerComandas', async (req, res) => {
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
const [results] = await connection.execute('SELECT * FROM comandas');
|
||||
res.json(results);
|
||||
} catch (error) {
|
||||
console.error('Error al obtener comandas:', error);
|
||||
res.status(500).json({ error: 'Error al obtener comandas' });
|
||||
} finally {
|
||||
if (connection) await connection.end();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
// ------------------------------------ CARGAS ----------------------------------------
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Cargar nueva mesa
|
||||
app.post('/api/cargarMesas', async (req, res) => {
|
||||
const { numero } = req.body;
|
||||
if (!numero) return res.status(400).json({ error: 'Falta el número de mesa' });
|
||||
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
await connection.execute('INSERT INTO mesas (numero) VALUES (?)', [numero]);
|
||||
res.status(201).json({ mensaje: 'Mesa cargada correctamente' });
|
||||
} catch (error) {
|
||||
console.error('Error al cargar mesa:', error);
|
||||
res.status(500).json({ error: 'Error al cargar mesa' });
|
||||
} finally {
|
||||
if (connection) await connection.end();
|
||||
}
|
||||
});
|
||||
|
||||
// Cargar nuevo producto
|
||||
app.post('/api/cargarProductos', async (req, res) => {
|
||||
const { nombre, precio, categoria_id } = req.body;
|
||||
if (!nombre || !precio || !categoria_id) {
|
||||
return res.status(400).json({ error: 'Faltan datos para cargar el producto' });
|
||||
}
|
||||
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
await connection.execute(
|
||||
'INSERT INTO productos (nombre, precio, categoria_id) VALUES (?, ?, ?)',
|
||||
[nombre, precio, categoria_id]
|
||||
);
|
||||
res.status(201).json({ mensaje: 'Producto cargado correctamente' });
|
||||
} catch (error) {
|
||||
console.error('Error al cargar producto:', error);
|
||||
res.status(500).json({ error: 'Error al cargar producto' });
|
||||
} finally {
|
||||
if (connection) await connection.end();
|
||||
}
|
||||
});
|
||||
|
||||
// Cargar nueva categoría
|
||||
app.post('/api/cargarCategorias', async (req, res) => {
|
||||
const { nombre } = req.body;
|
||||
if (!nombre) return res.status(400).json({ error: 'Falta el nombre de la categoría' });
|
||||
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
await connection.execute('INSERT INTO categorias (nombre) VALUES (?)', [nombre]);
|
||||
res.status(201).json({ mensaje: 'Categoría cargada correctamente' });
|
||||
} catch (error) {
|
||||
console.error('Error al cargar categoría:', error);
|
||||
res.status(500).json({ error: 'Error al cargar categoría' });
|
||||
} finally {
|
||||
if (connection) await connection.end();
|
||||
}
|
||||
});
|
||||
|
||||
// Cargar nueva comanda
|
||||
app.post('/api/cargarComandas', async (req, res) => {
|
||||
const { mesa_id, productos, total } = req.body;
|
||||
if (!mesa_id || !productos || !Array.isArray(productos) || total == null) {
|
||||
return res.status(400).json({ error: 'Datos inválidos para cargar comanda' });
|
||||
}
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
await connection.execute(
|
||||
'INSERT INTO comandas (mesa_id, productos, total, fecha) VALUES (?, ?, ?, NOW())',
|
||||
[mesa_id, JSON.stringify(productos), total]
|
||||
);
|
||||
res.status(201).json({ mensaje: 'Comanda cargada correctamente' });
|
||||
} catch (error) {
|
||||
console.error('Error al cargar comanda:', error);
|
||||
res.status(500).json({ error: 'Error al cargar comanda' });
|
||||
} finally {
|
||||
if (connection) await connection.end();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
// --------------------------------- VERIFICACIONES -----------------------------------
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
async function verificarConexion() {
|
||||
try {
|
||||
const connection = await mysql.createConnection(dbConfig);
|
||||
const [rows] = await connection.execute('SELECT NOW() AS hora');
|
||||
console.log('Conexión con la base de datos fue exitosa.');
|
||||
console.log('Fecha y hora actual de la base de datos:', rows[0].hora);
|
||||
await connection.end();
|
||||
} catch (error) {
|
||||
console.error('Error al conectar con la base de datos al iniciar:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Iniciar servidor
|
||||
app.listen(port, () => {
|
||||
console.log(`Servidor corriendo en http://localhost:${port}`);
|
||||
console.log('Estableciendo conexión...');
|
||||
verificarConexion();
|
||||
});
|
||||
@ -1,31 +0,0 @@
|
||||
# Dockerfile.prod
|
||||
FROM node:23-slim
|
||||
|
||||
# Definir variables de entorno con valores predeterminados
|
||||
ARG NODE_ENV=production
|
||||
ARG PORT=8080
|
||||
|
||||
# Definir las variables de entorno dentro del contenedor
|
||||
ENV NODE_ENV=${NODE_ENV}
|
||||
ENV PORT=${PORT}
|
||||
|
||||
# Crea directorio de trabajo
|
||||
WORKDIR /app
|
||||
|
||||
# Copia solo archivos necesarios para prod
|
||||
COPY package*.json ./
|
||||
|
||||
# Instala solo dependencias de producción
|
||||
RUN npm install --omit=dev
|
||||
|
||||
# Copia el resto de la app
|
||||
COPY . .
|
||||
|
||||
# Expone el puerto
|
||||
EXPOSE ${PORT}
|
||||
|
||||
# Ejecutar el servidor con nodemon en desarrollo, o con node en producción
|
||||
CMD ["npm", "start"]
|
||||
|
||||
# # Corre la app normalmente
|
||||
# CMD ["node", "src/index.js"]
|
||||
@ -1,28 +1,22 @@
|
||||
# Dockerfile.dev
|
||||
FROM node:23-slim
|
||||
FROM node:20.17
|
||||
|
||||
# Definir variables de entorno con valores predeterminados
|
||||
ARG NODE_ENV=development
|
||||
ARG PORT=3000
|
||||
|
||||
# Definir las variables de entorno dentro del contenedor
|
||||
ENV NODE_ENV=${NODE_ENV}
|
||||
ENV PORT=${PORT}
|
||||
|
||||
# Crea directorio de trabajo
|
||||
WORKDIR /app
|
||||
|
||||
# Copia archivos de configuración primero para aprovechar el cache
|
||||
COPY package*.json ./
|
||||
|
||||
# Instala dependencias (incluye devDependencies)
|
||||
RUN npm install
|
||||
# Instala dependencias
|
||||
RUN npm i express pg dotenv cors
|
||||
RUN npm i --save-dev nodemon
|
||||
|
||||
# Copia el resto de la app
|
||||
COPY . .
|
||||
|
||||
# Expone el puerto
|
||||
EXPOSE ${PORT}
|
||||
EXPOSE 3000
|
||||
|
||||
# Usa nodemon para hot reload si lo tenés
|
||||
CMD ["npx", "nodemon", "src/index.js"]
|
||||
CMD ["npm", "run", "dev"]
|
||||
1342
services/app/package-lock.json
generated
Normal file
1342
services/app/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
26
services/app/package.json
Normal file
26
services/app/package.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "app",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "NODE_ENV=production node ./src/index.js",
|
||||
"dev": "NODE_ENV=development node ./src/index.js",
|
||||
"test": "NODE_ENV=stage node ./src/index.js"
|
||||
},
|
||||
"author": "Mateo Saldain",
|
||||
"license": "ISC",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"cross-env": "^10.0.0",
|
||||
"nodemon": "^3.1.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^17.2.1",
|
||||
"express": "^5.1.0",
|
||||
"express-ejs-layouts": "^2.5.1",
|
||||
"pg": "^8.16.3"
|
||||
},
|
||||
"keywords": [],
|
||||
"description": ""
|
||||
}
|
||||
240
services/app/src/index.js
Normal file
240
services/app/src/index.js
Normal file
@ -0,0 +1,240 @@
|
||||
// app/src/index.js
|
||||
import express from 'express';
|
||||
import expressLayouts from 'express-ejs-layouts';
|
||||
import cors from 'cors';
|
||||
import { Pool } from 'pg';
|
||||
|
||||
// Rutas
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
// Variables de Entorno
|
||||
import dotenv, { config } from 'dotenv';
|
||||
|
||||
// Obtención de la ruta de la variable de entorno correspondiente a NODE_ENV
|
||||
try {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
dotenv.config({ path: path.resolve(__dirname, '../.env.development' )});
|
||||
console.log("Activando entorno de -> development");
|
||||
} else if (process.env.NODE_ENV === 'stage') {
|
||||
dotenv.config({ path: path.resolve(__dirname, '../.env.test' )});
|
||||
console.log("Activando entorno de -> testing");
|
||||
} else if (process.env.NODE_ENV === 'production') {
|
||||
dotenv.config({ path: path.resolve(__dirname, '../.env' )});
|
||||
console.log("Activando entorno de -> producción");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("A ocurrido un error al seleccionar el entorno. \nError: " + error);
|
||||
}
|
||||
|
||||
// Renderiado
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// Configuración de conexión PostgreSQL
|
||||
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_LOCAL_PORT
|
||||
};
|
||||
|
||||
const pool = new Pool(dbConfig);
|
||||
|
||||
|
||||
async function verificarConexion() {
|
||||
try {
|
||||
const client = await pool.connect();
|
||||
const res = await client.query('SELECT NOW() AS hora');
|
||||
console.log('Conexión con la base de datos fue exitosa.');
|
||||
console.log('Fecha y hora actual de la base de datos:', res.rows[0].hora);
|
||||
client.release(); // liberar el cliente de nuevo al pool
|
||||
} catch (error) {
|
||||
console.error('Error al conectar con la base de datos al iniciar:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// === Servir páginas estáticas ===
|
||||
app.use('/pages', express.static(path.join(__dirname, 'pages')));
|
||||
|
||||
|
||||
// Rutas de conveniencia para abrir cada página rápido:
|
||||
// (Opcional: puedes usar directamente /pages/roles.html, etc.)
|
||||
app.get('/roles', (req, res) => res.sendFile(path.join(__dirname, 'pages', 'roles.html')));
|
||||
app.get('/usuarios', (req, res) => res.sendFile(path.join(__dirname, 'pages', 'usuarios.html')));
|
||||
app.get('/categorias',(req, res) => res.sendFile(path.join(__dirname, 'pages', 'categorias.html')));
|
||||
app.get('/productos', (req, res) => res.sendFile(path.join(__dirname, 'pages', 'productos.html')));
|
||||
|
||||
|
||||
// Helper de consulta con acquire/release explícito
|
||||
async function q(text, params) {
|
||||
const client = await pool.connect();
|
||||
try {
|
||||
return await client.query(text, params);
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
|
||||
// === API Roles ===
|
||||
// GET: listar
|
||||
app.get('/api/roles', async (req, res) => {
|
||||
try {
|
||||
const { rows } = await q('SELECT id_rol, nombre FROM roles ORDER BY id_rol ASC');
|
||||
res.json(rows);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.status(500).json({ error: 'No se pudo listar roles' });
|
||||
}
|
||||
});
|
||||
|
||||
// POST: crear
|
||||
app.post('/api/roles', async (req, res) => {
|
||||
try {
|
||||
const { nombre } = req.body;
|
||||
if (!nombre || !nombre.trim()) return res.status(400).json({ error: 'Nombre requerido' });
|
||||
const { rows } = await q(
|
||||
'INSERT INTO roles (nombre) VALUES ($1) RETURNING id_rol, nombre',
|
||||
[nombre.trim()]
|
||||
);
|
||||
res.status(201).json(rows[0]);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
// Manejo de único/duplicado
|
||||
if (e.code === '23505') return res.status(409).json({ error: 'El rol ya existe' });
|
||||
res.status(500).json({ error: 'No se pudo crear el rol' });
|
||||
}
|
||||
});
|
||||
|
||||
// === API Usuarios ===
|
||||
// GET: listar
|
||||
app.get('/api/usuarios', async (req, res) => {
|
||||
try {
|
||||
const { rows } = await q(`
|
||||
SELECT id_usuario, documento, img_perfil, nombre, apellido, correo, telefono, fec_nacimiento, activo
|
||||
FROM usuarios
|
||||
ORDER BY id_usuario ASC
|
||||
`);
|
||||
res.json(rows);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.status(500).json({ error: 'No se pudo listar usuarios' });
|
||||
}
|
||||
});
|
||||
|
||||
// POST: crear
|
||||
app.post('/api/usuarios', async (req, res) => {
|
||||
try {
|
||||
const { documento, nombre, apellido, correo, telefono, fec_nacimiento } = req.body;
|
||||
if (!nombre || !apellido) return res.status(400).json({ error: 'Nombre y apellido requeridos' });
|
||||
|
||||
const { rows } = await q(`
|
||||
INSERT INTO usuarios (documento, nombre, apellido, correo, telefono, fec_nacimiento)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id_usuario, documento, nombre, apellido, correo, telefono, fec_nacimiento, activo
|
||||
`, [
|
||||
documento || null,
|
||||
nombre.trim(),
|
||||
apellido.trim(),
|
||||
correo || null,
|
||||
telefono || null,
|
||||
fec_nacimiento || null
|
||||
]);
|
||||
|
||||
res.status(201).json(rows[0]);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
if (e.code === '23505') return res.status(409).json({ error: 'Documento/Correo/Teléfono ya existe' });
|
||||
res.status(500).json({ error: 'No se pudo crear el usuario' });
|
||||
}
|
||||
});
|
||||
|
||||
// === API Categorías ===
|
||||
// GET: listar
|
||||
app.get('/api/categorias', async (req, res) => {
|
||||
try {
|
||||
const { rows } = await q('SELECT id_categoria, nombre, visible FROM categorias ORDER BY id_categoria ASC');
|
||||
res.json(rows);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.status(500).json({ error: 'No se pudo listar categorías' });
|
||||
}
|
||||
});
|
||||
|
||||
// POST: crear
|
||||
app.post('/api/categorias', async (req, res) => {
|
||||
try {
|
||||
const { nombre, visible } = req.body;
|
||||
if (!nombre || !nombre.trim()) return res.status(400).json({ error: 'Nombre requerido' });
|
||||
const vis = (typeof visible === 'boolean') ? visible : true;
|
||||
|
||||
const { rows } = await q(`
|
||||
INSERT INTO categorias (nombre, visible)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id_categoria, nombre, visible
|
||||
`, [nombre.trim(), vis]);
|
||||
|
||||
res.status(201).json(rows[0]);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
if (e.code === '23505') return res.status(409).json({ error: 'La categoría ya existe' });
|
||||
res.status(500).json({ error: 'No se pudo crear la categoría' });
|
||||
}
|
||||
});
|
||||
|
||||
// === API Productos ===
|
||||
// GET: listar
|
||||
app.get('/api/productos', async (req, res) => {
|
||||
try {
|
||||
const { rows } = await q(`
|
||||
SELECT id_producto, nombre, img_producto, precio, activo, id_categoria
|
||||
FROM productos
|
||||
ORDER BY id_producto ASC
|
||||
`);
|
||||
res.json(rows);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.status(500).json({ error: 'No se pudo listar productos' });
|
||||
}
|
||||
});
|
||||
|
||||
// POST: crear
|
||||
app.post('/api/productos', async (req, res) => {
|
||||
try {
|
||||
let { nombre, id_categoria, precio } = req.body;
|
||||
if (!nombre || !nombre.trim()) return res.status(400).json({ error: 'Nombre requerido' });
|
||||
id_categoria = parseInt(id_categoria, 10);
|
||||
precio = parseFloat(precio);
|
||||
if (!Number.isInteger(id_categoria)) return res.status(400).json({ error: 'id_categoria inválido' });
|
||||
if (!(precio >= 0)) return res.status(400).json({ error: 'precio inválido' });
|
||||
|
||||
const { rows } = await q(`
|
||||
INSERT INTO productos (nombre, id_categoria, precio)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id_producto, nombre, precio, activo, id_categoria
|
||||
`, [nombre.trim(), id_categoria, precio]);
|
||||
|
||||
res.status(201).json(rows[0]);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
// FK categories / checks
|
||||
if (e.code === '23503') return res.status(400).json({ error: 'La categoría no existe' });
|
||||
res.status(500).json({ error: 'No se pudo crear el producto' });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
app.use(expressLayouts);
|
||||
// Iniciar servidor
|
||||
app.listen( process.env.PORT, () => {
|
||||
console.log(`Servidor corriendo en http://localhost:${process.env.PORT}`);
|
||||
console.log('Estableciendo conexión con la db...');
|
||||
verificarConexion();
|
||||
});
|
||||
70
services/app/src/pages/categorias.html
Normal file
70
services/app/src/pages/categorias.html
Normal file
@ -0,0 +1,70 @@
|
||||
<!doctype html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Categorías</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Categorías</h1>
|
||||
|
||||
<h2>Crear categoría</h2>
|
||||
<form id="form-categoria">
|
||||
<label>Nombre:
|
||||
<input type="text" name="nombre" required />
|
||||
</label>
|
||||
<label>Visible:
|
||||
<select name="visible">
|
||||
<option value="true" selected>Sí</option>
|
||||
<option value="false">No</option>
|
||||
</select>
|
||||
</label>
|
||||
<button type="submit">Guardar</button>
|
||||
</form>
|
||||
|
||||
<h2>Listado</h2>
|
||||
<button id="btn-recargar">Recargar</button>
|
||||
<table border="1" cellpadding="6">
|
||||
<thead><tr><th>ID</th><th>Nombre</th><th>Visible</th></tr></thead>
|
||||
<tbody id="tbody"></tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
const API = '/api/categorias';
|
||||
|
||||
async function listar() {
|
||||
const res = await fetch(API);
|
||||
const data = await res.json();
|
||||
const tbody = document.getElementById('tbody');
|
||||
tbody.innerHTML = '';
|
||||
data.forEach(c => {
|
||||
const tr = document.createElement('tr');
|
||||
tr.innerHTML = `<td>${c.id_categoria}</td><td>${c.nombre}</td><td>${c.visible ? 'Sí' : 'No'}</td>`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('form-categoria').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const fd = new FormData(e.target);
|
||||
const nombre = fd.get('nombre').trim();
|
||||
const visible = fd.get('visible') === 'true';
|
||||
if (!nombre) return;
|
||||
const res = await fetch(API, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ nombre, visible })
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(()=>({error:'Error'}));
|
||||
alert('Error: ' + (err.error || res.statusText));
|
||||
return;
|
||||
}
|
||||
e.target.reset();
|
||||
await listar();
|
||||
});
|
||||
|
||||
document.getElementById('btn-recargar').addEventListener('click', listar);
|
||||
listar();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
106
services/app/src/pages/productos.html
Normal file
106
services/app/src/pages/productos.html
Normal file
@ -0,0 +1,106 @@
|
||||
<!doctype html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Productos</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Productos</h1>
|
||||
|
||||
<h2>Crear producto</h2>
|
||||
<form id="form-producto">
|
||||
<div>
|
||||
<label>Nombre:
|
||||
<input name="nombre" type="text" required />
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Precio:
|
||||
<input name="precio" type="number" step="0.01" min="0" required />
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Categoría:
|
||||
<select name="id_categoria" id="sel-categoria" required></select>
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit">Guardar</button>
|
||||
</form>
|
||||
|
||||
<h2>Listado</h2>
|
||||
<button id="btn-recargar">Recargar</button>
|
||||
<table border="1" cellpadding="6">
|
||||
<thead>
|
||||
<tr><th>ID</th><th>Nombre</th><th>Precio</th><th>Activo</th><th>ID Categoría</th></tr>
|
||||
</thead>
|
||||
<tbody id="tbody"></tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
const API = '/api/productos';
|
||||
const API_CAT = '/api/categorias';
|
||||
|
||||
async function cargarCategorias() {
|
||||
const res = await fetch(API_CAT);
|
||||
const data = await res.json();
|
||||
const sel = document.getElementById('sel-categoria');
|
||||
sel.innerHTML = '<option value="" disabled selected>Seleccione...</option>';
|
||||
data.forEach(c => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = c.id_categoria;
|
||||
opt.textContent = `${c.id_categoria} - ${c.nombre}`;
|
||||
sel.appendChild(opt);
|
||||
});
|
||||
}
|
||||
|
||||
async function listar() {
|
||||
const res = await fetch(API);
|
||||
const data = await res.json();
|
||||
const tbody = document.getElementById('tbody');
|
||||
tbody.innerHTML = '';
|
||||
data.forEach(p => {
|
||||
const tr = document.createElement('tr');
|
||||
tr.innerHTML = `
|
||||
<td>${p.id_producto}</td>
|
||||
<td>${p.nombre}</td>
|
||||
<td>${Number(p.precio).toFixed(2)}</td>
|
||||
<td>${p.activo ? 'Sí' : 'No'}</td>
|
||||
<td>${p.id_categoria}</td>
|
||||
`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('form-producto').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const fd = new FormData(e.target);
|
||||
const payload = {
|
||||
nombre: fd.get('nombre').trim(),
|
||||
precio: parseFloat(fd.get('precio')),
|
||||
id_categoria: parseInt(fd.get('id_categoria'), 10)
|
||||
};
|
||||
if (!payload.nombre || isNaN(payload.precio) || isNaN(payload.id_categoria)) return;
|
||||
|
||||
const res = await fetch(API, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(()=>({error:'Error'}));
|
||||
alert('Error: ' + (err.error || res.statusText));
|
||||
return;
|
||||
}
|
||||
e.target.reset();
|
||||
await listar();
|
||||
});
|
||||
|
||||
document.getElementById('btn-recargar').addEventListener('click', listar);
|
||||
|
||||
(async () => {
|
||||
await cargarCategorias();
|
||||
await listar();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
62
services/app/src/pages/roles.html
Normal file
62
services/app/src/pages/roles.html
Normal file
@ -0,0 +1,62 @@
|
||||
<!doctype html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Roles</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Roles</h1>
|
||||
|
||||
<h2>Crear rol</h2>
|
||||
<form id="form-rol">
|
||||
<label>Nombre del rol:
|
||||
<input type="text" name="nombre" required />
|
||||
</label>
|
||||
<button type="submit">Guardar</button>
|
||||
</form>
|
||||
|
||||
<h2>Listado</h2>
|
||||
<button id="btn-recargar">Recargar</button>
|
||||
<table border="1" cellpadding="6">
|
||||
<thead><tr><th>ID</th><th>Nombre</th></tr></thead>
|
||||
<tbody id="tbody"></tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
const API = '/api/roles';
|
||||
|
||||
async function listar() {
|
||||
const res = await fetch(API);
|
||||
const data = await res.json();
|
||||
const tbody = document.getElementById('tbody');
|
||||
tbody.innerHTML = '';
|
||||
data.forEach(r => {
|
||||
const tr = document.createElement('tr');
|
||||
tr.innerHTML = `<td>${r.id_rol}</td><td>${r.nombre}</td>`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('form-rol').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const nombre = e.target.nombre.value.trim();
|
||||
if (!nombre) return;
|
||||
const res = await fetch(API, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ nombre })
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(()=>({error:'Error'}));
|
||||
alert('Error: ' + (err.error || res.statusText));
|
||||
return;
|
||||
}
|
||||
e.target.reset();
|
||||
await listar();
|
||||
});
|
||||
|
||||
document.getElementById('btn-recargar').addEventListener('click', listar);
|
||||
listar();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
104
services/app/src/pages/usuarios.html
Normal file
104
services/app/src/pages/usuarios.html
Normal file
@ -0,0 +1,104 @@
|
||||
<!doctype html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Usuarios</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Usuarios</h1>
|
||||
|
||||
<h2>Crear usuario</h2>
|
||||
<form id="form-usuario">
|
||||
<div>
|
||||
<label>Documento:
|
||||
<input name="documento" type="text" />
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Nombre:
|
||||
<input name="nombre" type="text" required />
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Apellido:
|
||||
<input name="apellido" type="text" required />
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Correo:
|
||||
<input name="correo" type="email" />
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Teléfono:
|
||||
<input name="telefono" type="text" />
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Fecha de nacimiento:
|
||||
<input name="fec_nacimiento" type="date" />
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit">Guardar</button>
|
||||
</form>
|
||||
|
||||
<h2>Listado</h2>
|
||||
<button id="btn-recargar">Recargar</button>
|
||||
<table border="1" cellpadding="6">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th><th>Documento</th><th>Nombre</th><th>Apellido</th>
|
||||
<th>Correo</th><th>Teléfono</th><th>Nacimiento</th><th>Activo</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbody"></tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
const API = '/api/usuarios';
|
||||
|
||||
async function listar() {
|
||||
const res = await fetch(API);
|
||||
const data = await res.json();
|
||||
const tbody = document.getElementById('tbody');
|
||||
tbody.innerHTML = '';
|
||||
data.forEach(u => {
|
||||
const tr = document.createElement('tr');
|
||||
tr.innerHTML = `
|
||||
<td>${u.id_usuario}</td>
|
||||
<td>${u.documento ?? ''}</td>
|
||||
<td>${u.nombre}</td>
|
||||
<td>${u.apellido}</td>
|
||||
<td>${u.correo ?? ''}</td>
|
||||
<td>${u.telefono ?? ''}</td>
|
||||
<td>${u.fec_nacimiento ? u.fec_nacimiento.substring(0,10) : ''}</td>
|
||||
<td>${u.activo ? 'Sí' : 'No'}</td>
|
||||
`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('form-usuario').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const fd = new FormData(e.target);
|
||||
const payload = Object.fromEntries(fd.entries());
|
||||
if (payload.fec_nacimiento === '') delete payload.fec_nacimiento;
|
||||
const res = await fetch(API, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(()=>({error:'Error'}));
|
||||
alert('Error: ' + (err.error || res.statusText));
|
||||
return;
|
||||
}
|
||||
e.target.reset();
|
||||
await listar();
|
||||
});
|
||||
|
||||
document.getElementById('btn-recargar').addEventListener('click', listar);
|
||||
listar();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
22
services/auth/Dockerfile.development
Normal file
22
services/auth/Dockerfile.development
Normal file
@ -0,0 +1,22 @@
|
||||
# Dockerfile.dev
|
||||
FROM node:20.17
|
||||
|
||||
# Definir variables de entorno con valores predeterminados
|
||||
ARG NODE_ENV=development
|
||||
ARG PORT=3000
|
||||
|
||||
# Copia archivos de configuración primero para aprovechar el cache
|
||||
COPY package*.json ./
|
||||
|
||||
# Instala dependencias
|
||||
RUN npm i express pg dotenv cors
|
||||
RUN npm i --save-dev nodemon
|
||||
|
||||
# Copia el resto de la app
|
||||
COPY . .
|
||||
|
||||
# Expone el puerto
|
||||
EXPOSE 3000
|
||||
|
||||
# Usa nodemon para hot reload si lo tenés
|
||||
CMD ["npm", "run", "dev"]
|
||||
405
package-lock.json → services/auth/package-lock.json
generated
405
package-lock.json → services/auth/package-lock.json
generated
@ -1,23 +1,32 @@
|
||||
{
|
||||
"name": "suitecoffee",
|
||||
"name": "auth",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "suitecoffee",
|
||||
"name": "auth",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.5.0",
|
||||
"dotenv": "^17.2.1",
|
||||
"express": "^5.1.0",
|
||||
"mysql2": "^3.14.0"
|
||||
"express-ejs-layouts": "^2.5.1",
|
||||
"pg": "^8.16.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.1.9"
|
||||
"cross-env": "^10.0.0",
|
||||
"nodemon": "^3.1.10"
|
||||
}
|
||||
},
|
||||
"node_modules/@epic-web/invariant": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@epic-web/invariant/-/invariant-1.0.0.tgz",
|
||||
"integrity": "sha512-lrTPqgvfFQtR/eY/qkIzp98OGdNJu0m5ji3q/nJI8v3SXkRKEnWiOxMmbvcSoAIzv/cGiuvRy57k4suKQSAdwA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
|
||||
@ -45,15 +54,6 @@
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/aws-ssl-profiles": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz",
|
||||
"integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/balanced-match": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||
@ -95,9 +95,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
||||
"version": "1.1.12",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz",
|
||||
"integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@ -240,10 +240,43 @@
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/cross-env": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cross-env/-/cross-env-10.0.0.tgz",
|
||||
"integrity": "sha512-aU8qlEK/nHYtVuN4p7UQgAwVljzMg8hB4YK5ThRqD2l/ziSnryncPNn7bMLt5cFYsKVKBh8HqLqyCoTupEUu7Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@epic-web/invariant": "^1.0.0",
|
||||
"cross-spawn": "^7.0.6"
|
||||
},
|
||||
"bin": {
|
||||
"cross-env": "dist/bin/cross-env.js",
|
||||
"cross-env-shell": "dist/bin/cross-env-shell.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
"version": "7.0.6",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"path-key": "^3.1.0",
|
||||
"shebang-command": "^2.0.0",
|
||||
"which": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz",
|
||||
"integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==",
|
||||
"version": "4.4.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz",
|
||||
"integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
@ -257,15 +290,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/denque": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz",
|
||||
"integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/depd": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||
@ -276,9 +300,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.5.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz",
|
||||
"integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==",
|
||||
"version": "17.2.1",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.1.tgz",
|
||||
"integrity": "sha512-kQhDYKZecqnM0fCnzI5eIv5L4cAe/iRI+HqMbO/hbRdTAeXDG+M9FjipUxNfbARuEg4iHIbhnhs78BCHNbSxEQ==",
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
@ -403,6 +427,11 @@
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/express-ejs-layouts": {
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmjs.org/express-ejs-layouts/-/express-ejs-layouts-2.5.1.tgz",
|
||||
"integrity": "sha512-IXROv9n3xKga7FowT06n1Qn927JR8ZWDn5Dc9CJQoiiaaDqbhW5PDmWShzbpAa2wjWT1vJqaIM1S6vJwwX11gA=="
|
||||
},
|
||||
"node_modules/fill-range": {
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||
@ -475,15 +504,6 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/generate-function": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz",
|
||||
"integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"is-property": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
@ -596,6 +616,15 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/http-errors/node_modules/statuses": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
|
||||
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/iconv-lite": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
|
||||
@ -682,41 +711,12 @@
|
||||
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/is-property": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz",
|
||||
"integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/long": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz",
|
||||
"integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/lru-cache": {
|
||||
"version": "7.18.3",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
|
||||
"integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/lru.min": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.2.tgz",
|
||||
"integrity": "sha512-Nv9KddBcQSlQopmBHXSsZVY5xsdlZkdH/Iey0BlcBYggMd4two7cZnKOK9vmy3nY0O5RGH99z1PCeTpPqszUYg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"bun": ">=1.0.0",
|
||||
"deno": ">=1.30.0",
|
||||
"node": ">=8.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wellwelwel"
|
||||
}
|
||||
"node_modules/isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
@ -788,38 +788,6 @@
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/mysql2": {
|
||||
"version": "3.14.0",
|
||||
"resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.14.0.tgz",
|
||||
"integrity": "sha512-8eMhmG6gt/hRkU1G+8KlGOdQi2w+CgtNoD1ksXZq9gQfkfDsX4LHaBwTe1SY0Imx//t2iZA03DFnyYKPinxSRw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"aws-ssl-profiles": "^1.1.1",
|
||||
"denque": "^2.1.0",
|
||||
"generate-function": "^2.3.1",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"long": "^5.2.1",
|
||||
"lru.min": "^1.0.0",
|
||||
"named-placeholders": "^1.1.3",
|
||||
"seq-queue": "^0.0.5",
|
||||
"sqlstring": "^2.3.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/named-placeholders": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz",
|
||||
"integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"lru-cache": "^7.14.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/negotiator": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
|
||||
@ -830,9 +798,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/nodemon": {
|
||||
"version": "3.1.9",
|
||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.9.tgz",
|
||||
"integrity": "sha512-hdr1oIb2p6ZSxu3PB2JWWYS7ZQ0qvaZsc3hK8DR8f02kRzc8rjYmxAIvdz+aYC+8F2IjNaB7HMcSDg8nQpJxyg==",
|
||||
"version": "3.1.10",
|
||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.10.tgz",
|
||||
"integrity": "sha512-WDjw3pJ0/0jMFmyNDp3gvY2YizjLmmOUQo6DEBY+JgdvW/yQ9mEeSw6H5ythl5Ny2ytb7f9C2nIbjSxMNzbJXw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@ -919,6 +887,16 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/path-key": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
|
||||
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/path-to-regexp": {
|
||||
"version": "8.2.0",
|
||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz",
|
||||
@ -928,6 +906,95 @@
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"node_modules/pg": {
|
||||
"version": "8.16.3",
|
||||
"resolved": "https://registry.npmjs.org/pg/-/pg-8.16.3.tgz",
|
||||
"integrity": "sha512-enxc1h0jA/aq5oSDMvqyW3q89ra6XIIDZgCX9vkMrnz5DFTw/Ny3Li2lFQ+pt3L6MCgm/5o2o8HW9hiJji+xvw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"pg-connection-string": "^2.9.1",
|
||||
"pg-pool": "^3.10.1",
|
||||
"pg-protocol": "^1.10.3",
|
||||
"pg-types": "2.2.0",
|
||||
"pgpass": "1.0.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"pg-cloudflare": "^1.2.7"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"pg-native": ">=3.0.1"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"pg-native": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/pg-cloudflare": {
|
||||
"version": "1.2.7",
|
||||
"resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.2.7.tgz",
|
||||
"integrity": "sha512-YgCtzMH0ptvZJslLM1ffsY4EuGaU0cx4XSdXLRFae8bPP4dS5xL1tNB3k2o/N64cHJpwU7dxKli/nZ2lUa5fLg==",
|
||||
"license": "MIT",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/pg-connection-string": {
|
||||
"version": "2.9.1",
|
||||
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.9.1.tgz",
|
||||
"integrity": "sha512-nkc6NpDcvPVpZXxrreI/FOtX3XemeLl8E0qFr6F2Lrm/I8WOnaWNhIPK2Z7OHpw7gh5XJThi6j6ppgNoaT1w4w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/pg-int8": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
|
||||
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/pg-pool": {
|
||||
"version": "3.10.1",
|
||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.10.1.tgz",
|
||||
"integrity": "sha512-Tu8jMlcX+9d8+QVzKIvM/uJtp07PKr82IUOYEphaWcoBhIYkoHpLXN3qO59nAI11ripznDsEzEv8nUxBVWajGg==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"pg": ">=8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/pg-protocol": {
|
||||
"version": "1.10.3",
|
||||
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.10.3.tgz",
|
||||
"integrity": "sha512-6DIBgBQaTKDJyxnXaLiLR8wBpQQcGWuAESkRBX/t6OwA8YsqP+iVSiond2EDy6Y/dsGk8rh/jtax3js5NeV7JQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/pg-types": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
|
||||
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"pg-int8": "1.0.1",
|
||||
"postgres-array": "~2.0.0",
|
||||
"postgres-bytea": "~1.0.0",
|
||||
"postgres-date": "~1.0.4",
|
||||
"postgres-interval": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/pgpass": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
|
||||
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"split2": "^4.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/picomatch": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
||||
@ -941,6 +1008,45 @@
|
||||
"url": "https://github.com/sponsors/jonschlinkert"
|
||||
}
|
||||
},
|
||||
"node_modules/postgres-array": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
|
||||
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/postgres-bytea": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
|
||||
"integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/postgres-date": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
|
||||
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/postgres-interval": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
|
||||
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-addr": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||
@ -1056,9 +1162,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/semver": {
|
||||
"version": "7.7.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
|
||||
"integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==",
|
||||
"version": "7.7.2",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",
|
||||
"integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==",
|
||||
"dev": true,
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
@ -1090,11 +1196,6 @@
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/seq-queue": {
|
||||
"version": "0.0.5",
|
||||
"resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz",
|
||||
"integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q=="
|
||||
},
|
||||
"node_modules/serve-static": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz",
|
||||
@ -1116,6 +1217,29 @@
|
||||
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/shebang-command": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"shebang-regex": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/shebang-regex": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
|
||||
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
|
||||
@ -1201,19 +1325,19 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/sqlstring": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz",
|
||||
"integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==",
|
||||
"license": "MIT",
|
||||
"node_modules/split2": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
|
||||
"integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
"node": ">= 10.x"
|
||||
}
|
||||
},
|
||||
"node_modules/statuses": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
|
||||
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
|
||||
"integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
@ -1303,11 +1427,36 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
|
||||
"dev": true,
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"isexe": "^2.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"node-which": "bin/node-which"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/xtend": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
services/auth/package.json
Normal file
26
services/auth/package.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "auth",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "NODE_ENV=production node ./src/index.js",
|
||||
"dev": "NODE_ENV=development node ./src/index.js",
|
||||
"test": "NODE_ENV=stage node ./src/index.js"
|
||||
},
|
||||
"author": "Mateo Saldain",
|
||||
"license": "ISC",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"cross-env": "^10.0.0",
|
||||
"nodemon": "^3.1.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^17.2.1",
|
||||
"express": "^5.1.0",
|
||||
"express-ejs-layouts": "^2.5.1",
|
||||
"pg": "^8.16.3"
|
||||
},
|
||||
"keywords": [],
|
||||
"description": ""
|
||||
}
|
||||
79
services/auth/src/index.js
Normal file
79
services/auth/src/index.js
Normal file
@ -0,0 +1,79 @@
|
||||
// auth/src/index.js
|
||||
import express from 'express';
|
||||
import expressLayouts from 'express-ejs-layouts';
|
||||
import cors from 'cors';
|
||||
import { Pool } from 'pg';
|
||||
|
||||
// Rutas
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
// Variables de Entorno
|
||||
import dotenv, { config } from 'dotenv';
|
||||
|
||||
// Obtención de la ruta de la variable de entorno correspondiente a NODE_ENV
|
||||
try {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
dotenv.config({ path: path.resolve(__dirname, '../.env.development' )});
|
||||
console.log("Activando entorno de -> development");
|
||||
} else if (process.env.NODE_ENV === 'stage') {
|
||||
dotenv.config({ path: path.resolve(__dirname, '../.env.test' )});
|
||||
console.log("Activando entorno de -> testing");
|
||||
} else if (process.env.NODE_ENV === 'production') {
|
||||
dotenv.config({ path: path.resolve(__dirname, '../.env' )});
|
||||
console.log("Activando entorno de -> producción");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("A ocurrido un error al seleccionar el entorno. \nError: " + error);
|
||||
}
|
||||
|
||||
// Renderiado
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// Configuración de conexión PostgreSQL
|
||||
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_LOCAL_PORT
|
||||
};
|
||||
|
||||
const pool = new Pool(dbConfig);
|
||||
|
||||
|
||||
async function verificarConexion() {
|
||||
try {
|
||||
const client = await pool.connect();
|
||||
const res = await client.query('SELECT NOW() AS hora');
|
||||
console.log('Conexión con la base de datos fue exitosa.');
|
||||
console.log('Fecha y hora actual de la base de datos:', res.rows[0].hora);
|
||||
client.release(); // liberar el cliente de nuevo al pool
|
||||
} catch (error) {
|
||||
console.error('Error al conectar con la base de datos al iniciar:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// === Servir páginas estáticas ===
|
||||
app.use('/pages', express.static(path.join(__dirname, 'pages')));
|
||||
|
||||
|
||||
// Rutas de conveniencia para abrir cada página rápido:
|
||||
// (Opcional: puedes usar directamente /pages/roles.html, etc.)
|
||||
app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'pages', 'index.html')));
|
||||
|
||||
|
||||
app.use(expressLayouts);
|
||||
// Iniciar servidor
|
||||
app.listen( process.env.PORT, () => {
|
||||
console.log(`Servidor corriendo en http://localhost:${process.env.PORT}`);
|
||||
console.log('Estableciendo conexión con la db...');
|
||||
verificarConexion();
|
||||
});
|
||||
@ -12,15 +12,19 @@
|
||||
|
||||
<div class="card shadow p-4" style="width: 100%; max-width: 350px;">
|
||||
<h4 class="text-center mb-4">Iniciar Sesión</h4>
|
||||
<form>
|
||||
|
||||
<form id="form-login">
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="usuario" class="form-label">Usuario</label>
|
||||
<input type="text" class="form-control" id="usuario" placeholder="Ingrese su usuario" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="clave" class="form-label">Contraseña</label>
|
||||
<input type="password" class="form-control" id="clave" placeholder="Ingrese su contraseña" required>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="recordarme">
|
||||
@ -30,6 +34,7 @@
|
||||
</div>
|
||||
<a href="#" class="small">¿Olvidaste tu contraseña?</a>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-100">Entrar</button>
|
||||
</form>
|
||||
</div>
|
||||
@ -1,100 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Comanda - Cafetería</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
|
||||
<div class="container my-4">
|
||||
<div class="card shadow">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h4 class="mb-0">🧾 Comanda de Cafetería</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form>
|
||||
<!-- Datos generales -->
|
||||
<div class="row g-3 mb-4">
|
||||
<div class="col-12 col-md-6">
|
||||
<label for="mesa" class="form-label">Número de Mesa</label>
|
||||
<select class="form-select" id="mesa" required>
|
||||
<option value="">Seleccionar mesa</option>
|
||||
<option>Mesa 1</option>
|
||||
<option>Mesa 2</option>
|
||||
<option>Mesa 3</option>
|
||||
<option>Mesa 4</option>
|
||||
<option>Mesa 5</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-12 col-md-6">
|
||||
<label for="mozo" class="form-label">Mozo/a</label>
|
||||
<input type="text" class="form-control" id="mozo" placeholder="Nombre del mozo/a" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Productos -->
|
||||
<div class="mb-4">
|
||||
<label class="form-label">Productos</label>
|
||||
|
||||
<!-- Producto 1 -->
|
||||
<div class="row g-2 mb-2">
|
||||
<div class="col-12 col-md-6">
|
||||
<select class="form-select">
|
||||
<option value="">Seleccionar producto</option>
|
||||
<option>Café</option>
|
||||
<option>Café con leche</option>
|
||||
<option>Capuccino</option>
|
||||
<option>Medialuna</option>
|
||||
<option>Jugo natural</option>
|
||||
<option>Tostado</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-6 col-md-3">
|
||||
<input type="number" class="form-control" placeholder="Cant.">
|
||||
</div>
|
||||
<div class="col-6 col-md-3">
|
||||
<input type="text" class="form-control" placeholder="Notas">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Producto 2 -->
|
||||
<div class="row g-2 mb-2">
|
||||
<div class="col-12 col-md-6">
|
||||
<select class="form-select">
|
||||
<option value="">Seleccionar producto</option>
|
||||
<option>Café</option>
|
||||
<option>Café con leche</option>
|
||||
<option>Capuccino</option>
|
||||
<option>Medialuna</option>
|
||||
<option>Jugo natural</option>
|
||||
<option>Tostado</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-6 col-md-3">
|
||||
<input type="number" class="form-control" placeholder="Cant.">
|
||||
</div>
|
||||
<div class="col-6 col-md-3">
|
||||
<input type="text" class="form-control" placeholder="Notas">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Observaciones -->
|
||||
<div class="mb-4">
|
||||
<label for="observaciones" class="form-label">Observaciones</label>
|
||||
<textarea class="form-control" id="observaciones" rows="3" placeholder="Ej: Sin azúcar, entregar cuando esté completo"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-success">Enviar Comanda</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user