Login
This commit is contained in:
+40
-19
@@ -7,35 +7,56 @@ const admin = require("./tablas/Admin");
|
||||
require("../config/config");
|
||||
|
||||
async function remove() {
|
||||
console.log(logSymbols.info, "Paso 1 : Borrando base de datos \n".blue.bold);
|
||||
console.log(logSymbols.info, "Paso 1 : Borrando base de datos \n".blue.bold);
|
||||
|
||||
await admin.drop();
|
||||
console.log(logSymbols.success, "admin");
|
||||
await admin.drop();
|
||||
console.log(logSymbols.success, "admin");
|
||||
|
||||
}
|
||||
|
||||
async function install() {
|
||||
console.log(
|
||||
logSymbols.info,
|
||||
"Paso 2 : Instalando base de datos \n".blue.bold
|
||||
);
|
||||
console.log(
|
||||
logSymbols.info,
|
||||
"Paso 2 : Instalando base de datos \n".blue.bold
|
||||
);
|
||||
|
||||
await admin.sync();
|
||||
console.log(logSymbols.success, "admin");
|
||||
await admin.sync();
|
||||
console.log(logSymbols.success, "admin");
|
||||
|
||||
//crear clave foranea de una tabla a otra, ejemplo
|
||||
// responsable.hasMany(programa, {
|
||||
// foreignKey: "idResponsable",
|
||||
// });
|
||||
|
||||
};
|
||||
|
||||
async function createFirstUsers() {
|
||||
console.log(
|
||||
logSymbols.info,
|
||||
"Paso 3 : Creating first users in database...\n".blue.bold
|
||||
);
|
||||
|
||||
await admin.create({
|
||||
name: 'alima',
|
||||
password: bcrypt.hashSync('contraseña', 10),
|
||||
isAdmin: true
|
||||
});
|
||||
|
||||
await admin.create({
|
||||
name: 'alfredojl',
|
||||
password: bcrypt.hashSync('contraseña', 10),
|
||||
isAdmin: false
|
||||
});
|
||||
|
||||
//crear clave foranea de una tabla a otra, ejemplo
|
||||
// responsable.hasMany(programa, {
|
||||
// foreignKey: "idResponsable",
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
async function exec() {
|
||||
await remove();
|
||||
await install();
|
||||
await remove();
|
||||
await install();
|
||||
await createFirstUsers();
|
||||
|
||||
console.log(logSymbols.success, "Éxito al instalar \n".underline.bold.green);
|
||||
process.exit();
|
||||
console.log(logSymbols.success, "Éxito al instalar \n".underline.bold.green);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
exec();
|
||||
exec();
|
||||
@@ -2,27 +2,28 @@ const Sequelize = require("sequelize");
|
||||
const sequelize = require("../../config/sequelize.conf");
|
||||
|
||||
class Admin extends Sequelize.Model {}
|
||||
Admin.init(
|
||||
{
|
||||
Admin.init({
|
||||
idAdmin: {
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
allowNull: false,
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
allowNull: false,
|
||||
},
|
||||
nombre: {
|
||||
type: Sequelize.STRING(50),
|
||||
allowNull: false,
|
||||
name: {
|
||||
type: Sequelize.STRING(50),
|
||||
allowNull: false,
|
||||
},
|
||||
password: {
|
||||
type: Sequelize.STRING(100),
|
||||
allowNull: false,
|
||||
type: Sequelize.STRING(100),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
isAdmin: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
tableName: "admin",
|
||||
}
|
||||
);
|
||||
tableName: "users",
|
||||
});
|
||||
|
||||
module.exports = Admin;
|
||||
module.exports = Admin;
|
||||
Reference in New Issue
Block a user