Skip to content

Commit

Permalink
fix: corrijo typos
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalaciosg committed Aug 23, 2021
1 parent 266f538 commit 135c888
Show file tree
Hide file tree
Showing 27 changed files with 2,593 additions and 36 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified Práctica Web JS-Node-Mongo - Web 7.pdf
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified nodepop/.eslintrc.json
100644 → 100755
Empty file.
10 changes: 5 additions & 5 deletions nodepop/app.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ app.use(function(req, res, next) {

// error handler
app.use(function(err, req, res, next) {
// comprueba error de validaciòn
// comprueba error de validación
if (err.array) {
err.status = 422;
const errInfo = err.array({ onlyFirstError: true })[0];
err.message = isAPI(req)
? {message: 'Not valid', errors: err.mapped()}
: `Not valid - ${errInfo.param} ${errInfo.msg}`;
err.message = isAPI(req)
? {message: 'Not valid', errors: err.mapped()}
: `Not valid - ${errInfo.param} ${errInfo.msg}`;
}
res.status(err.status || 500);
if(isAPI(req)) {
Expand All @@ -66,7 +66,7 @@ app.use(function(err, req, res, next) {
res.render('error');
});

// funcion para saber si es una petición a un API
// función para saber si es una petición a un API
function isAPI(req) {
return req.originalUrl.indexOf('/api') === 0;
}
Expand Down
Empty file modified nodepop/controllers/AnuncioController.js
100644 → 100755
Empty file.
Empty file modified nodepop/data/anuncios.json
100644 → 100755
Empty file.
36 changes: 18 additions & 18 deletions nodepop/install_db.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
'use strict';
"use strict";

const fs = require('fs');
const fs = require("fs");
const fsPromises = fs.promises;

const mongoose = require('mongoose');
const conn = require('./lib/connectDB');
const Anuncio = require('./models/Anuncio');
const mongoose = require("mongoose");
const conn = require("./lib/connectDB");
const Anuncio = require("./models/Anuncio");

const file = './data/anuncios.json';
const data = JSON.parse(fs.readFileSync(file,'utf-8'));
const file = "./data/anuncios.json";
const data = JSON.parse(fs.readFileSync(file,"utf-8"));

// conectar
mongoose.connect('mongodb://localhost/nodepop' , { useNewUrlParser: true, useUnifiedTopology: true });
mongoose.connect("mongodb://127.0.0.1/nodepop" , { useNewUrlParser: true, useUnifiedTopology: true });


async function cleanAgentes() {
try {
const resDel = await Anuncio.deleteMany({});
console.log('Base de datos borrada!', resDel.ok, resDel.deletedCount);
console.log("Base de datos borrada!", resDel.ok, resDel.deletedCount);
} catch (err) {
console.log('Erro al limpiar Anuncios', err);
console.log("Erro al limpiar Anuncios", err);

}
}

async function loadAnuncios() {
try {
await Anuncio.insertMany(data.anuncios);
console.log('Datos de anuncios cargados.!');
console.log("Datos de anuncios cargados.!");
} catch (err) {
console.log(`Error al cargar archivo ${file}, >>>> ${err}`);
process.exit();
}
}

// gestionar eventos de conexión
conn.on('error', err => {
console.log('Error de conexión', err);
conn.on("error", err => {
console.log("Error de conexión", err);
process.exit(1);
});

// Proceso de Inicialización Base de datos una vez conectado a mongodb
conn.once('open', async () => {
console.log('Conectado a MongoDB en ', mongoose.connection.name);
console.log('Limpiando Base de datos..!');
conn.once("open", async () => {
console.log("Conectado a MongoDB en ", mongoose.connection.name);
console.log("Limpiando Base de datos..!");
await cleanAgentes();
console.log('Cargando anuncios.json!');
console.log("Cargando anuncios.json!");
await loadAnuncios();
console.log('Terminado..!');
console.log("Terminado..!");
process.exit();
});
8 changes: 4 additions & 4 deletions nodepop/lib/connectDB.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const conn = mongoose.connection;

mongoose.set('useFindAndModify', false);

// gestionar eventos de conexion
// gestionar eventos de conexión
conn.on("error", err => {
console.log("Error de conexiòn", err);
console.log("Error de conexión", err);
process.exit(1);
});

Expand All @@ -17,7 +17,7 @@ conn.once("open", () => {
});

// conectar
mongoose.connect("mongodb://localhost/nodepop", { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true });
mongoose.connect("mongodb://127.0.0.1/nodepop", { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true });

// exportar la conexiòn
// exportar la conexión
module.exports = conn;
Empty file modified nodepop/models/Anuncio.js
100644 → 100755
Empty file.
Loading

0 comments on commit 135c888

Please sign in to comment.