Skip to content

Commit 5974dd9

Browse files
Agrego frontend inicial
0 parents  commit 5974dd9

64 files changed

Lines changed: 46538 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env"
4+
]
5+
}

backend/.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"tabWidth": 2,
4+
"trailingComma": "none"
5+
}

backend/.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

backend/TODO.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
| Cargo | C
2+
| Cliente | C
3+
| DetallesVenta | C
4+
| Empleado | C
5+
| Plato | C
6+
| Provision | C
7+
| TipoUsuario | C
8+
| Usuario | C
9+
| Venta | C
10+
11+
12+
- Encripar y desencriptar contraseña
13+
- Validación de campos desde SQL
14+
- Proteger rutas

backend/package-lock.json

Lines changed: 5835 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "SistemaRestaurante",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1",
7+
"start": "nodemon --exec babel-node server/app.js"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"cors": "^2.8.5",
14+
"dotenv": "^8.2.0",
15+
"express": "^4.17.1",
16+
"joi": "^17.4.0",
17+
"jsonwebtoken": "^8.5.1",
18+
"morgan": "^1.10.0",
19+
"mysql2": "^2.2.5"
20+
},
21+
"devDependencies": {
22+
"@babel/core": "^7.13.16",
23+
"@babel/node": "^7.13.13",
24+
"@babel/preset-env": "^7.13.15"
25+
},
26+
"description": ""
27+
}

backend/server/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { Server } from './models/Server';
2+
import './config/db';
3+
4+
new Server().listen();
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
-- Created by Vertabelo (http://vertabelo.com)
2+
-- Last modification date: 2021-04-27 17:31:11.32
3+
4+
-- tables
5+
6+
-- Table: Cliente
7+
CREATE TABLE Cliente (
8+
id_cliente int NOT NULL AUTO_INCREMENT,
9+
nombres varchar(255) NULL,
10+
apellidos varchar(255) NOT NULL,
11+
estado bit NOT NULL DEFAULT 1,
12+
CONSTRAINT Cliente_pk PRIMARY KEY (id_cliente)
13+
);
14+
15+
-- Table: DetallesVenta
16+
CREATE TABLE DetallesVenta (
17+
id_detalle_venta int NOT NULL AUTO_INCREMENT,
18+
id_venta int NOT NULL,
19+
id_plato int NOT NULL,
20+
cantidad int NOT NULL DEFAULT 1,
21+
estado bit NOT NULL DEFAULT 1,
22+
CONSTRAINT DetallesVenta_pk PRIMARY KEY (id_detalle_venta)
23+
);
24+
25+
-- Table: Empleado
26+
CREATE TABLE Empleado (
27+
id_empleado int NOT NULL AUTO_INCREMENT,
28+
nombres varchar(255) NOT NULL,
29+
apellidos varchar(255) NOT NULL,
30+
fotografia varchar(255) NULL,
31+
telefono int NOT NULL,
32+
sexo char(1) NOT NULL,
33+
estado bit NOT NULL DEFAULT 1,
34+
CONSTRAINT Empleado_pk PRIMARY KEY (id_empleado)
35+
);
36+
37+
-- Table: Plato
38+
CREATE TABLE Plato (
39+
id_plato int NOT NULL AUTO_INCREMENT,
40+
nombre varchar(255) NOT NULL,
41+
precio decimal(6,2) NOT NULL,
42+
descripcion varchar(255) NOT NULL,
43+
imagen varchar(255) NULL,
44+
estado bit NOT NULL DEFAULT 1,
45+
CONSTRAINT Plato_pk PRIMARY KEY (id_plato)
46+
);
47+
48+
-- Table: Provision
49+
CREATE TABLE Provision (
50+
id_provision int NOT NULL AUTO_INCREMENT,
51+
id_plato int NOT NULL,
52+
cantidad_disponible int NOT NULL DEFAULT 0,
53+
CONSTRAINT Provision_pk PRIMARY KEY (id_provision)
54+
);
55+
56+
-- Table: TipoUsuario
57+
CREATE TABLE TipoUsuario (
58+
id_tipo_usuario int NOT NULL AUTO_INCREMENT,
59+
nombre_tipo_usuario varchar(255) NOT NULL,
60+
estado bit NOT NULL DEFAULT 1,
61+
CONSTRAINT TipoUsuario_pk PRIMARY KEY (id_tipo_usuario)
62+
);
63+
64+
-- Table: Usuario
65+
CREATE TABLE Usuario (
66+
id_usuario int NOT NULL AUTO_INCREMENT,
67+
id_empleado int NOT NULL,
68+
id_tipo_usuario int NOT NULL,
69+
nombre_usuario varchar(255) NOT NULL,
70+
contrasenia varchar(255) NOT NULL,
71+
estado bit NOT NULL DEFAULT 1,
72+
CONSTRAINT Usuario_pk PRIMARY KEY (id_usuario)
73+
);
74+
75+
-- Table: Venta
76+
CREATE TABLE Venta (
77+
id_venta int NOT NULL AUTO_INCREMENT,
78+
id_usuario int NOT NULL,
79+
id_cliente int NOT NULL,
80+
total decimal(6,2) NOT NULL,
81+
fecha timestamp DEFAULT CURRENT_TIMESTAMP,
82+
estado bit NOT NULL DEFAULT 1,
83+
CONSTRAINT Venta_pk PRIMARY KEY (id_venta)
84+
);
85+
86+
-- foreign keys
87+
-- Reference: DetallesVenta_Plato (table: DetallesVenta)
88+
ALTER TABLE DetallesVenta ADD CONSTRAINT DetallesVenta_Plato FOREIGN KEY DetallesVenta_Plato (id_plato)
89+
REFERENCES Plato (id_plato);
90+
91+
-- Reference: DetallesVenta_Venta (table: DetallesVenta)
92+
ALTER TABLE DetallesVenta ADD CONSTRAINT DetallesVenta_Venta FOREIGN KEY DetallesVenta_Venta (id_venta)
93+
REFERENCES Venta (id_venta);
94+
95+
96+
-- Reference: Provision_Plato (table: Provision)
97+
ALTER TABLE Provision ADD CONSTRAINT Provision_Plato FOREIGN KEY Provision_Plato (id_plato)
98+
REFERENCES Plato (id_plato);
99+
100+
-- Reference: Usuario_Empleado (table: Usuario)
101+
ALTER TABLE Usuario ADD CONSTRAINT Usuario_Empleado FOREIGN KEY Usuario_Empleado (id_empleado)
102+
REFERENCES Empleado (id_empleado);
103+
104+
-- Reference: Usuario_TipoUsuario (table: Usuario)
105+
ALTER TABLE Usuario ADD CONSTRAINT Usuario_TipoUsuario FOREIGN KEY Usuario_TipoUsuario (id_tipo_usuario)
106+
REFERENCES TipoUsuario (id_tipo_usuario);
107+
108+
-- Reference: Venta_Cliente (table: Venta)
109+
ALTER TABLE Venta ADD CONSTRAINT Venta_Cliente FOREIGN KEY Venta_Cliente (id_cliente)
110+
REFERENCES Cliente (id_cliente);
111+
112+
-- Reference: Venta_Usuario (table: Venta)
113+
ALTER TABLE Venta ADD CONSTRAINT Venta_Usuario FOREIGN KEY Venta_Usuario (id_usuario)
114+
REFERENCES Usuario (id_usuario);
115+
116+
-- End of file.
117+

backend/server/config/db.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as dotenv from 'dotenv';
2+
dotenv.config();
3+
4+
import mysql from 'mysql2';
5+
6+
export const pool = mysql.createPool({
7+
host: process.env.HOST,
8+
user: process.env.USER_DB,
9+
password: process.env.PASSWORD,
10+
database: process.env.DATABASE,
11+
connectionLimit: 10
12+
});
13+
14+
export const promisePool = pool.promise();
15+
16+
export const connectDB = pool.getConnection((err, connection) => {
17+
if (err) throw err;
18+
//TODO: capturar los errores más comunes
19+
20+
promisePool.getConnection();
21+
22+
console.log('Database connection established');
23+
return;
24+
});
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import * as Cliente from '../models/Cliente';
2+
3+
export const seleccionarById = async (req, res) => {
4+
const { id } = res.locals.paramsValidado;
5+
6+
try {
7+
const data = await Cliente.seleccionarById(id);
8+
9+
if (data.length > 0) {
10+
return res.json({ msg: 'Registro obtenido', data: data[0] });
11+
}
12+
13+
res.status(404).json({
14+
msg: `No se encontraron registros con el id: "${id}"`
15+
});
16+
} catch (err) {
17+
console.log(err);
18+
res.status(500).json({ msg: 'Comuniquese con el administrador' });
19+
}
20+
};
21+
22+
export const seleccionar = async (req, res) => {
23+
let { desde, limite } = res.locals.queryValidado;
24+
25+
//Se resta uno porque inicia en la posicion cero, si no manda nada por defecto sera cero.
26+
desde = desde - 1 || 0;
27+
//si no manda nada el cliente, por defecto el limite seran diez registros
28+
limite = limite || 10;
29+
30+
try {
31+
const data = await Cliente.seleccionar(desde, limite);
32+
33+
if (data[0]) {
34+
return res.json({
35+
msg: 'Registros obtenidos',
36+
data
37+
});
38+
}
39+
40+
res.status(404).json({
41+
msg: 'No se encontraron registros',
42+
data
43+
});
44+
} catch (err) {
45+
console.log(err);
46+
res.status(500).json({ msg: 'Comuniquese con el administrador' });
47+
}
48+
};
49+
50+
export const insertar = async (req, res) => {
51+
const nuevoCliente = res.locals.bodyValidado;
52+
53+
try {
54+
const data = await Cliente.insertar(nuevoCliente);
55+
56+
if (data[0].affectedRows === 1) {
57+
return res.json({
58+
msg: 'El registro ha sido insertado',
59+
data: { id: data[0].insertId, ...nuevoCliente }
60+
});
61+
}
62+
63+
res.status(400).json({
64+
ok: false,
65+
msg: 'El registro no fue insertado'
66+
});
67+
} catch (err) {
68+
console.log(err);
69+
res.status(500).json({ msg: 'Comuniquese con el administrador' });
70+
}
71+
};
72+
73+
export const actualizar = async (req, res) => {
74+
const { id } = res.locals.paramsValidado;
75+
const nuevoCliente = res.locals.bodyValidado;
76+
77+
try {
78+
const data = await Cliente.actualizar(id, nuevoCliente);
79+
80+
if (data.affectedRows == 1 && data.changedRows == 1) {
81+
return res.json({
82+
msg: 'El registro ha sido actualizado',
83+
data: { id, ...nuevoCliente }
84+
});
85+
}
86+
87+
if (data.affectedRows == 1 && data.changedRows == 0) {
88+
return res.json({
89+
msg: 'El registro enviado es igual que el existente',
90+
data: { id, ...nuevoCliente }
91+
});
92+
}
93+
94+
res.status(400).json({
95+
msg: `No se encontró registro con id: ${id}`
96+
});
97+
} catch (err) {
98+
console.log(err);
99+
res.status(500).json({ msg: 'Comuniquese con el administrador' });
100+
}
101+
};
102+
103+
export const eliminar = async (req, res) => {
104+
const { id } = res.locals.paramsValidado;
105+
106+
try {
107+
const data = await Cliente.eliminar(id);
108+
109+
if (data.affectedRows == 1 && data.changedRows == 1) {
110+
return res.json({ msg: `El registro con id: ${id} ha sido eliminado` });
111+
}
112+
113+
res.status(404).json({ msg: `No se encontró registro con id: ${id}` });
114+
} catch (err) {
115+
console.log(err);
116+
res.status(500).json({ msg: 'Comuniquese con el administrador' });
117+
}
118+
};

0 commit comments

Comments
 (0)