tablas
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
.env
|
||||
node_modules/
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 2,
|
||||
"semi": true,
|
||||
"singleQuote": true
|
||||
}
|
||||
Generated
+5088
File diff suppressed because it is too large
Load Diff
+19
-1
@@ -11,5 +11,23 @@
|
||||
"url": "https://repositorio.acatlan.unam.mx/CIDWA/servicio_social_api.git"
|
||||
},
|
||||
"author": "cidwa",
|
||||
"license": "ISC"
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bcrypt": "^5.0.0",
|
||||
"body-parser": "^1.19.0",
|
||||
"colors": "^1.4.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mariadb": "^2.5.1",
|
||||
"moment": "^2.29.1",
|
||||
"multer": "^1.4.2",
|
||||
"mysql2": "^2.2.5",
|
||||
"sequelize": "^6.3.5",
|
||||
"validator": "^13.1.17"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
require('./config/config');
|
||||
const colors = require('colors');
|
||||
const bodyParser = require('body-parser');
|
||||
const cors = require('cors');
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
app.use(cors());
|
||||
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
extended: false,
|
||||
})
|
||||
);
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.get('/', (req, res) => res.send('API PCPUMA'));
|
||||
|
||||
app.use(require('./routes/index'));
|
||||
|
||||
app.listen(process.env.PORT, () =>
|
||||
console.log(`API PCPUMA corriendo en el puerto: ${process.env.PORT}`.rainbow)
|
||||
);
|
||||
@@ -0,0 +1,27 @@
|
||||
const dotenv = require('dotenv');
|
||||
const colors = require('colors');
|
||||
var result = {};
|
||||
|
||||
try {
|
||||
result = dotenv.config();
|
||||
if (result.error) throw result.error;
|
||||
console.log('El archivo .env se cargado correctamente.'.underline.bold.cyan);
|
||||
} catch (err) {
|
||||
console.log('El archivo .env no se cargo.'.underline.bold.red);
|
||||
}
|
||||
|
||||
// process.env.TYPEDB = process.env.TYPEDB
|
||||
|
||||
// process.env.DB = process.env.DB
|
||||
|
||||
// process.env.USERDB = process.env.USERDB
|
||||
|
||||
// process.env.PASSWORDDB = process.env.PASSWORDDB
|
||||
|
||||
// process.env.HOSTDB = process.env.HOSTDB
|
||||
|
||||
// process.env.PORT = process.env.PORT
|
||||
|
||||
// process.env.SALT_ROUNDS = process.env.SALT_ROUNDS
|
||||
|
||||
process.env.CADUCIDAD_TOKEN = 60 * 60 * 24 ;
|
||||
@@ -0,0 +1,19 @@
|
||||
require('./config');
|
||||
const { Sequelize } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize(
|
||||
process.env.DB,
|
||||
process.env.USERDB,
|
||||
process.env.PASSWORDDB,
|
||||
{
|
||||
host: process.env.HOSTDB,
|
||||
dialect: process.env.TYPEDB,
|
||||
logging: false,
|
||||
dialectOptions: {
|
||||
useUTC: false,
|
||||
},
|
||||
timezone: '-05:00',
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = sequelize;
|
||||
@@ -0,0 +1,13 @@
|
||||
const sequelize = require('./sequelize.conf');
|
||||
require('colors');
|
||||
|
||||
sequelize
|
||||
.authenticate()
|
||||
.then(() => {
|
||||
console.log('Se ha conectado a la base de datos exitosamente.'.green);
|
||||
process.exit();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Hubo un error al conectarse a la base de datos: '.red, err);
|
||||
process.exit();
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
const colors = require('colors');
|
||||
const Arrendamiento = require('./tablas/Arrendamiento');
|
||||
const Foto = require('./tablas/Foto');
|
||||
const Inmueble = require('./tablas/Inmueble');
|
||||
const InmuebleTipoCuarto = require('./tablas/InmuebleTipoCuarto');
|
||||
const Mes = require('./tablas/Mes');
|
||||
const Tarjeta = require('./tablas/Tarjeta');
|
||||
const TipoCuarto = require('./tablas/TipoCuarto');
|
||||
const Usuario = require('./tablas/Usuario');
|
||||
|
||||
const drop = async () => {
|
||||
console.log('\nPaso 1) Desinstalando la db.'.bold.blue);
|
||||
|
||||
await Mes.drop();
|
||||
console.log('La tabla Mes se instalo correctamente.'.magenta);
|
||||
|
||||
await Arrendamiento.drop();
|
||||
console.log('La tabla Arrendamiento se instalo correctamente.'.magenta);
|
||||
|
||||
await InmuebleTipoCuarto.drop();
|
||||
console.log('La tabla InmuebleTipoCuarto se instalo correctamente.'.magenta);
|
||||
|
||||
await TipoCuarto.drop();
|
||||
console.log('La tabla TipoCuarto se instalo correctamente.'.magenta);
|
||||
|
||||
await Foto.drop();
|
||||
console.log('La tabla Foto se instalo correctamente.'.magenta);
|
||||
|
||||
await Inmueble.drop();
|
||||
console.log('La tabla Inmueble se instalo correctamente.'.magenta);
|
||||
|
||||
await Tarjeta.drop();
|
||||
console.log('La tabla Tarjeta se instalo correctamente.'.magenta);
|
||||
|
||||
await Usuario.drop();
|
||||
console.log('La tabla Usuario se instalo correctamente.'.magenta);
|
||||
};
|
||||
|
||||
const sync = async () => {
|
||||
console.log('\nPaso 2) Instalando la db.'.bold.blue);
|
||||
|
||||
await Usuario.sync();
|
||||
console.log('La tabla Usuario se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Tarjeta.sync();
|
||||
console.log('La tabla Tarjeta se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Inmueble.sync();
|
||||
console.log('La tabla Inmueble se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Foto.sync();
|
||||
console.log('La tabla Foto se desinstalo correctamente.'.magenta);
|
||||
|
||||
await TipoCuarto.sync();
|
||||
console.log('La tabla TipoCuarto se desinstalo correctamente.'.magenta);
|
||||
|
||||
await InmuebleTipoCuarto.sync();
|
||||
console.log(
|
||||
'La tabla InmuebleTipoCuarto se desinstalo correctamente.'.magenta
|
||||
);
|
||||
|
||||
await Arrendamiento.sync();
|
||||
console.log('La tabla Arrendamiento se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Mes.sync();
|
||||
console.log('La tabla Mes se desinstalo correctamente.'.magenta);
|
||||
};
|
||||
|
||||
const dataTipoCuarto = async () => {
|
||||
const data = [
|
||||
'Cuartos',
|
||||
'Cocinas',
|
||||
'Baños',
|
||||
'Salas',
|
||||
'Comedores',
|
||||
'Espacios para automóviles',
|
||||
'Otros',
|
||||
];
|
||||
|
||||
console.log('\nPaso 3) Instalando catálogos.'.bold.blue);
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
await TipoCuarto.create({ tipoCuarto: data[i] })
|
||||
.then((res) => console.log(`Se creo el TipoCuarto ${res.tipoCuarto}`.red))
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
};
|
||||
|
||||
const exe = async () => {
|
||||
await drop();
|
||||
await sync();
|
||||
await dataTipoCuarto();
|
||||
console.log(
|
||||
'\nSe ha instalado exitosamente la base de datos.\n'.underline.bold.green
|
||||
);
|
||||
|
||||
process.exit();
|
||||
};
|
||||
|
||||
exe();
|
||||
@@ -0,0 +1,27 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
class Carrera extends Model {}
|
||||
Carrera.init(
|
||||
{
|
||||
idCarrera: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
carrera: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Carrera',
|
||||
tableName: 'carrera',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = Carrera;
|
||||
@@ -0,0 +1,155 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
class CuestionarioAlumno extends Model {}
|
||||
CuestionarioAlumno.init(
|
||||
{
|
||||
idCuestionarioAlumno: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
sexo: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
edad: {
|
||||
type: DataTypes.STRING(2),
|
||||
allowNull: false,
|
||||
},
|
||||
servicioMedico: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
},
|
||||
pUno: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pDos: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pTres: {
|
||||
type: DataTypes.STRING(150),
|
||||
allowNull: false,
|
||||
},
|
||||
pCuatro: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pCinco: {
|
||||
type: DataTypes.STRING(7),
|
||||
allowNull: false,
|
||||
},
|
||||
pSeis: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pSiete: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pOcho: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: false,
|
||||
},
|
||||
pNueve: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pDiez: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pOnce: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pDoce: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pTrece: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pCatorce: {
|
||||
type: DataTypes.STRING(7),
|
||||
allowNull: false,
|
||||
},
|
||||
pQuince: {
|
||||
type: DataTypes.STRING(7),
|
||||
allowNull: false,
|
||||
},
|
||||
pDieciseis: {
|
||||
type: DataTypes.STRING(2),
|
||||
allowNull: false,
|
||||
},
|
||||
pDiecisiete: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: false,
|
||||
},
|
||||
pDieciocho: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pDiecinueve: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pVeinte: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pVeintiuno: {
|
||||
type: DataTypes.STRING(9),
|
||||
allowNull: false,
|
||||
},
|
||||
pVeintidos: {
|
||||
type: DataTypes.STRING(23),
|
||||
allowNull: false,
|
||||
},
|
||||
pVeintitres: {
|
||||
type: DataTypes.STRING(8),
|
||||
allowNull: false,
|
||||
},
|
||||
pVeinticuatro: {
|
||||
type: DataTypes.STRING(8),
|
||||
allowNull: false,
|
||||
},
|
||||
pVeinticinco: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pVeintiseis: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pVeintisiete: {
|
||||
type: DataTypes.STRING(400),
|
||||
allowNull: false,
|
||||
},
|
||||
pVeintiocho: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pVeintinueve: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
pTreinta: {
|
||||
type: DataTypes.STRING(400),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'CuestionarioAlumno',
|
||||
tableName: 'cuestionario_alumno',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = CuestionarioAlumno;
|
||||
@@ -0,0 +1,55 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
class CuestionarioPrograma extends Model {}
|
||||
CuestionarioPrograma.init(
|
||||
{
|
||||
idCuestionarioPrograma: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
actividadUno: {
|
||||
type: DataTypes.STRING(400),
|
||||
allowNull: false,
|
||||
},
|
||||
actividadDos: {
|
||||
type: DataTypes.STRING(400),
|
||||
allowNull: false,
|
||||
},
|
||||
actividadTres: {
|
||||
type: DataTypes.STRING(400),
|
||||
allowNull: false,
|
||||
},
|
||||
actividadCuatro: {
|
||||
type: DataTypes.STRING(400),
|
||||
allowNull: false,
|
||||
},
|
||||
actividadCinco: {
|
||||
type: DataTypes.STRING(400),
|
||||
allowNull: false,
|
||||
},
|
||||
retroalimentacion: {
|
||||
type: DataTypes.STRING(9),
|
||||
allowNull: false,
|
||||
},
|
||||
pSeis: {
|
||||
type: DataTypes.STRING(500),
|
||||
allowNull: false,
|
||||
},
|
||||
pSiete: {
|
||||
type: DataTypes.STRING(800),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'CuestionarioPrograma',
|
||||
tableName: 'cuestionario_programa',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = CuestionarioPrograma;
|
||||
@@ -0,0 +1,53 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Usuario = require('./Usuario');
|
||||
|
||||
class Programa extends Model {}
|
||||
Programa.init(
|
||||
{
|
||||
idPrograma: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
institucion: {
|
||||
type: DataTypes.STRING(60),
|
||||
allowNull: false,
|
||||
},
|
||||
dependencia: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: false,
|
||||
},
|
||||
programa: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: false,
|
||||
},
|
||||
clavePrograma: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: false,
|
||||
},
|
||||
activo: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Programa',
|
||||
tableName: 'programa',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
Programa.belongsTo(Usuario, {
|
||||
foreignKey: {
|
||||
name: 'idUsuario',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Programa;
|
||||
@@ -0,0 +1,142 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Usuario = require('./Usuario');
|
||||
const Carrera = require('./Carrera');
|
||||
const Programa = require('./Programa');
|
||||
const Status = require('./Status');
|
||||
const CuestionarioAlumno = require('./CuestionarioAlumno');
|
||||
const CuestionarioPrograma = require('./CuestionarioPrograma');
|
||||
|
||||
class Servicio extends Model {}
|
||||
Servicio.init(
|
||||
{
|
||||
idServicio: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
creditos: {
|
||||
type: DataTypes.STRING(3),
|
||||
allowNull: false,
|
||||
},
|
||||
nombre: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: false,
|
||||
},
|
||||
correo: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: false,
|
||||
},
|
||||
telefono: {
|
||||
type: DataTypes.STRING(10),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
direccion: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
fechaInicio: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
fechaFin: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
fechaNacimiento: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
cartaAceptacion: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: false,
|
||||
},
|
||||
cartaTermino: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
informeGlobal: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
programaInterno: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
profesor: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
vistoBuenoAcatlan: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Servicio',
|
||||
tableName: 'servicio',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
Servicio.belongsTo(Usuario, {
|
||||
foreignKey: {
|
||||
name: 'idUsuario',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
Servicio.belongsTo(Carrera, {
|
||||
foreignKey: {
|
||||
name: 'idCarrera',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
Servicio.belongsTo(Status, {
|
||||
foreignKey: {
|
||||
name: 'idStatus',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
Servicio.belongsTo(Programa, {
|
||||
foreignKey: {
|
||||
name: 'idPrograma',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
Servicio.belongsTo(CuestionarioAlumno, {
|
||||
foreignKey: {
|
||||
name: 'idCuestionarioAlumno',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
Servicio.belongsTo(CuestionarioPrograma, {
|
||||
foreignKey: {
|
||||
name: 'idCuestionarioPrograma',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Servicio;
|
||||
@@ -0,0 +1,27 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
class Status extends Model {}
|
||||
Status.init(
|
||||
{
|
||||
idStatus: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Status',
|
||||
tableName: 'status',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = Status;
|
||||
@@ -0,0 +1,27 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
class TipoUsuario extends Model {}
|
||||
TipoUsuario.init(
|
||||
{
|
||||
idTipoUsuario: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
tipoUsuario: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'TipoUsuario',
|
||||
tableName: 'tipo_usuario',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = TipoUsuario;
|
||||
@@ -0,0 +1,44 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const TipoUsuario = require('./TipoUsuario');
|
||||
|
||||
class Usuario extends Model {}
|
||||
Usuario.init(
|
||||
{
|
||||
idUsuario: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
usuario: {
|
||||
type: DataTypes.STRING(60),
|
||||
allowNull: false,
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: false,
|
||||
},
|
||||
nombre: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Usuario',
|
||||
tableName: 'usuario',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
Usuario.belongsTo(TipoUsuario, {
|
||||
foreignKey: {
|
||||
name: 'idTipoUsuario',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Usuario;
|
||||
@@ -0,0 +1,23 @@
|
||||
const bcrypt = require('bcrypt');
|
||||
const validar = require('./validar');
|
||||
require('../config/config');
|
||||
|
||||
const comparar = (password, dbPassword) => {
|
||||
let campo = 'password';
|
||||
|
||||
validar.noHay(password, campo);
|
||||
if (typeof password != 'string') validar.noValido(campo);
|
||||
if (!bcrypt.compareSync(password, dbPassword))
|
||||
throw new Error('Usuario o contraseña no validos.');
|
||||
return true;
|
||||
};
|
||||
|
||||
const encriptar = (password) => {
|
||||
let campo = 'password';
|
||||
|
||||
validar.noHay(password, campo);
|
||||
if (typeof password != 'string') validar.noValido(campo);
|
||||
return bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
||||
};
|
||||
|
||||
module.exports = { comparar, encriptar };
|
||||
@@ -0,0 +1,50 @@
|
||||
const validator = require('validator');
|
||||
|
||||
const noValido = (campo) => {
|
||||
throw new Error(`El ${campo} no es valido.`);
|
||||
};
|
||||
|
||||
const noHay = (variable, campo) => {
|
||||
if (!variable) throw new Error(`Falta ${campo}.`);
|
||||
};
|
||||
|
||||
const yaExiste = (campo) => {
|
||||
throw new Error(`El ${campo} ya se encuentra en uso.`);
|
||||
};
|
||||
|
||||
const validarId = (id) => {
|
||||
let campo = 'id';
|
||||
|
||||
noHay(id, campo);
|
||||
if (typeof id === 'number') id = id.toString();
|
||||
if (typeof id !== 'string' || !validator.isNumeric(id, { no_symbols: true }))
|
||||
noValido(campo);
|
||||
return Number(id);
|
||||
};
|
||||
|
||||
const validarCorreo = (correo) => {
|
||||
let campo = 'correo';
|
||||
|
||||
noHay(correo, campo);
|
||||
if (typeof correo !== 'string' || !validator.isEmail(correo)) noValido(campo);
|
||||
return correo;
|
||||
};
|
||||
|
||||
const validarTexto = (texto, campo) => {
|
||||
noHay(texto, campo);
|
||||
if (typeof texto !== 'string') noValido(campo);
|
||||
for (let i = 0; i < texto.length; i++) {
|
||||
if (texto[i] === ' ') continue;
|
||||
if (!validator.isAlpha(texto[i], 'es-ES')) noValido(campo);
|
||||
}
|
||||
return texto;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validarCorreo,
|
||||
validarId,
|
||||
validarTexto,
|
||||
yaExiste,
|
||||
noValido,
|
||||
noHay,
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
require('../config/config');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
const verificaToken = (req, res, next) => {
|
||||
let token = req.headers.token;
|
||||
|
||||
if (!token)
|
||||
return res.status(401).json({
|
||||
message: 'No hay token',
|
||||
});
|
||||
jwt.verify(token, process.env.KEY, (err, decoded) => {
|
||||
if (err)
|
||||
return res.status(401).json({
|
||||
message: 'El token ya expiro.',
|
||||
});
|
||||
req.idUsuario = decoded.idUsuario;
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
const crearToken = (idUsuario) => {
|
||||
return jwt.sign({ idUsuario }, process.env.KEY, {
|
||||
expiresIn: process.env.CADUCIDAD_TOKEN,
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = { verificaToken, crearToken };
|
||||
@@ -0,0 +1,16 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const route = '/arrendamiento';
|
||||
// const get = require('../controller/TipoCuarto/get');
|
||||
|
||||
// app.get(`${route}`, (req, res) => {
|
||||
// return get()
|
||||
// .then((data) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(400).json(err);
|
||||
// });
|
||||
// });
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,16 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const route = '/inmueble';
|
||||
// const get = require('../controller/TipoCuarto/get');
|
||||
|
||||
// app.get(`${route}`, (req, res) => {
|
||||
// return get()
|
||||
// .then((data) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(400).json(err);
|
||||
// });
|
||||
// });
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,16 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const route = '/tarjeta';
|
||||
// const get = require('../controller/TipoCuarto/get');
|
||||
|
||||
// app.get(`${route}`, (req, res) => {
|
||||
// return get()
|
||||
// .then((data) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(400).json(err);
|
||||
// });
|
||||
// });
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,16 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const route = '/tipo_cuarto';
|
||||
const get = require('../controller/TipoCuarto/get');
|
||||
|
||||
app.get(`${route}`, (req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json(err);
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,27 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const route = '/usuario';
|
||||
const create = require('../controller/Usuario/create');
|
||||
const login = require('../controller/Usuario/login');
|
||||
|
||||
app.post(`${route}/create`, (req, res) => {
|
||||
return create(req.body)
|
||||
.then((data) => {
|
||||
res.status(201).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.post(`${route}/login`, (req, res) => {
|
||||
return login(req.body)
|
||||
.then((data) => {
|
||||
res.status(201).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,8 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
// app.use(require('./'))
|
||||
app.use(require('./TipoCuarto'));
|
||||
app.use(require('./Usuario'));
|
||||
|
||||
module.exports = app;
|
||||
Reference in New Issue
Block a user