<repo_name>SantiagoRMJ/mySql_project<file_sep>/app.js
const express = require('express');
const mysql = require('mysql2/promise');
const app = express();
const cors = require('cors')
app.use(express.json());
const routerUser = require('./routers/router_usuarios');
const routerCitas = require('./routers/router_citas');

const connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    database: 'clinicaDental_db',
    password: '<PASSWORD>'
})

//CORS
app.use(cors())

app.use('/usuario', routerUser);
app.use('/citas', routerCitas);

const PORT = process.env.PORT || 4000

app.listen(PORT, ()=> console.log('Servidor levantado en' + PORT));
['unhandledRejection', 'uncaughtException'].forEach(event => process.on(event, (err) => {
    console.error(`unhandled error: ${err.stack || err}`);
}));<file_sep>/routers/router_usuarios.js
const router = require('express').Router();
const services_usuarios = require('../services/services_usuarios.js');

router.post('/user', services_usuarios.registro);
router.get('/userlogin', services_usuarios.login);



module.exports = router;<file_sep>/routers/router_citas.js
const router = require('express').Router();
const service_citas = require('../services/services_citas');

router.get('/', service_citas.listarCitas);
router.get('/pending', service_citas.citasPendientes );
router.delete('/', service_citas.cancelarCita);
router.post('/', service_citas.crearCita);


module.exports = router;<file_sep>/services/services_usuarios.js
const sequelize = require('../models/index.js');


exports.registro = async (req, res) =>{
    
    
    let user = await user.create({
        nombre: req.body.nombre,
        apellidos: req.body.apellidos,
        nacimiento: req.body.nacimiento,
        telefono: req.body.telefono,
        direccion: req.body.direccion,
        covid: req.body.covid,
        password: <PASSWORD>,
        email: req.body.email,
        dni: req.body.dni
    })
    res.json({"message": 'usuario creado'}); 
};

exports.login = async (req, res)=>{
    const{user, password} = req.body;
    if(!user || !password) return res.json({error: 'faltan datos'});
    const data = await users.find(e => e.user === user && e.password === <PASSWORD>);
    if(!data) return res.json({error: 'ningún usuario coincide con tu usuario y contraseña'});
    return data;
};
<file_sep>/services/services_citas.js
const sequelize = require('../models/index.js');

exports.crearCita = async (req, res) =>{
    const {cliente_id, fecha, observaciones, precio, estado} = req.body;
    await sequelize.query(`INSERT INTO CITAS (cliente_id, fecha, observaciones, precio, estado)
    VALUES ('${cliente_id}', '${fecha}', '${observaciones}', '${precio}', '${estado}')`, {type: sequelize.QueryTypes.INSERT})
    return (citas => res.json(citas)) 
}
exports.listarCitas = async (req, res) =>{
    await sequelize.findAll(citas => res.json(citas))
    return citas
}
exports.citasPendientes = async (req, res) =>{
    await sequelize.query("SELECT * FROM CITAS WHERE estado = 'Pendiente'", {type: sequelize.QueryTypes.SELECT})
    return (citas => res.json(citas));     
}
exports.cancelarCita = async(req, res) =>{
    const id = req.body;   
    await sequelize.query(`DELETE FROM CITAS WHERE id_cliente = ${id}`, {type: sequelize.QueryTypes.DELETE})
    return (citas => res.json(citas))  
}
