diff --git a/APP/components/Formularios/Fcredito.vue b/APP/components/Formularios/Fcredito.vue new file mode 100644 index 0000000..924aaee --- /dev/null +++ b/APP/components/Formularios/Fcredito.vue @@ -0,0 +1,80 @@ + + + + + \ No newline at end of file diff --git a/APP/layouts/error.vue b/APP/layouts/error.vue index ff1b93a..99c6b17 100644 --- a/APP/layouts/error.vue +++ b/APP/layouts/error.vue @@ -1,14 +1,12 @@ \ No newline at end of file diff --git a/APP/pages/GeneralViews/NotFoundPage.vue b/APP/pages/GeneralViews/NotFoundPage.vue deleted file mode 100755 index 8e902d3..0000000 --- a/APP/pages/GeneralViews/NotFoundPage.vue +++ /dev/null @@ -1,40 +0,0 @@ - - - - diff --git a/APP/pages/creditos.vue b/APP/pages/creditos.vue index 259b3c0..3cac153 100644 --- a/APP/pages/creditos.vue +++ b/APP/pages/creditos.vue @@ -1,14 +1,363 @@ \ No newline at end of file diff --git a/APP/pages/register.vue b/APP/pages/register.vue index 302d518..2589431 100644 --- a/APP/pages/register.vue +++ b/APP/pages/register.vue @@ -87,10 +87,11 @@ export default { this.user.email = ""; }) .catch((e) => { + this.$notify({ type: "danger", icon: "tim-icons icon-alert-circle-exc", - message: "User already exists :(", + message: "No esta permitido la creaciøn de usuarios, o ya existe !!!", }); }); }, diff --git a/index.js b/index.js index a7ebf02..a35deae 100644 --- a/index.js +++ b/index.js @@ -28,8 +28,10 @@ app.use('/api',require('./routes/users')); app.use('/api',require('./routes/compras')) app.use('/api',require('./routes/ingresos')) app.use('/api',require('./routes/presupuesto')) +app.use('/api',require('./routes/creditos')) app.use('/api',require('./routes/categorias')) app.use('/api',require('./routes/metodos_pago')) +app.use("*",(req,res)=>{res.redirect("/")}) app.disable('x-powered-by'); module.exports = app; diff --git a/models/credito.js b/models/credito.js new file mode 100755 index 0000000..e337206 --- /dev/null +++ b/models/credito.js @@ -0,0 +1,23 @@ +const mongoose = require('mongoose'); +const {Schema} =mongoose; + +const itemSchema = new Schema({ + fecha:{type: String, required:true}, + detalle:{type:String}, + valor:{type:Number}, + tipo:{type:String, required:true} +}) + +const CreditoSchema=new Schema({ + date: {type: Date, default: Date.now}, + nombreCredito: {type:String,required:true}, + datos:[itemSchema], + valor: {type:Number, default:0}, + tasa_interes:{type:Number, default:0}, + user:{type:String, required:true}, + child:itemSchema + +}); + +module.exports.Credito=mongoose.model('creditos',CreditoSchema); +module.exports.itemCredito=mongoose.model('itemCredito',itemSchema); \ No newline at end of file diff --git a/routes/creditos.js b/routes/creditos.js new file mode 100644 index 0000000..562549a --- /dev/null +++ b/routes/creditos.js @@ -0,0 +1,114 @@ +const router = require("express").Router(); +const Credito = require("../models/credito").Credito; +const itemCredito = require("../models/credito").itemCredito; +const { checkAuth } = require("../middlewares/authentication"); + +router.get("/credito", checkAuth, async (req, res) => { + var creditos; + let limite = req.get('limite'); + creditos = await Credito.find({ user: req.userData._id }).sort({ + date: "desc", + }).limit(parseInt(limite)); + + + return res.send({ + status: "ok", + data: creditos, + }); +}); + +router.post("/credito", checkAuth, async (req, res) => { + const { nombreCredito,valor,tasa_interes } = req.body; + + var creditos = await Credito.find({ + user: req.userData._id, + nombreCredito: nombreCredito, + }); + + if (creditos.length == 0) { + const credito = new Credito({ + nombreCredito: nombreCredito, + valor:valor, + tasa_interes:tasa_interes + }); + + credito.user = req.userData._id; + await credito.save(); + + return res.json({ + status: "OK", + }); + } + + return res.status(500).json({ + status: "FAIL", + }); +}); + +router.delete("/credito", checkAuth, async (req, res) => { + try { + const userId = req.userData._id; + const id = req.query.id; + + const resultado = await Credito.deleteOne({ user: userId, _id: id }); + + return res.json({ status: "ok", data: resultado }); + } catch (error) { + console.log(error); + return res.status(500).json({ status: "fail", error: error }); + } +}); + +router.put("/credito", checkAuth, async (req, res) => { + const { _id, fecha, detalle, valor, tipo } = req.body; + const credito_edit = await Credito.findOne({ + _id: _id, + user: req.userData._id, + }); + const itemP = new itemCredito({ fecha,detalle, valor, tipo }); + credito_edit.datos.push(itemP); + await credito_edit.save(); + + res.json({ + status: "OK", + }); +}); + +router.get("/credito_items", checkAuth, async (req, res) => { + const _id = req.query.credito_id; + const credito_edit = await Credito.findOne({ + _id: _id, + user: req.userData._id, + }); + + return res.json({ + status: "OK", + data: credito_edit.datos, + }); +}); + +router.delete("/creditoitem", checkAuth, async (req, res) => { + try { + const userId = req.userData._id; + + const iditem = req.query.iditem; + const credito_id = req.query.idCredito; + + var credito_edit = await Credito.findOne({ + user: userId, + _id: credito_id, + }); + + console.log(credito_edit) + console.log("---------------") + credito_edit.datos.id(iditem).remove(); + await credito_edit.save(); + + return res.json({ status: "ok" }); + } catch (error) { + console.log(error); + return res.status(500).json({ status: "fail", error: error }); + } +}); + +module.exports = router; diff --git a/routes/users.js b/routes/users.js index b54f44f..f95d25a 100644 --- a/routes/users.js +++ b/routes/users.js @@ -2,54 +2,72 @@ const express = require("express"); const router = express.Router(); const jwt = require("jsonwebtoken"); const bcrypt = require("bcrypt"); -const User = require("../models/user") +const User = require("../models/user"); //import User from "../models/user.js"; //AUTH -router.post("/register", async (req, res) => { - const { name, email, password } = req.body; - const passEncrypted = bcrypt.hashSync(password, 10); - const newUser = new User({ - name: name, - email: email, - password: password, - }); +if (process.env.REGISTER == "true") { + router.post("/register", async (req, res) => { + const { name, email, password } = req.body; + const passEncrypted = bcrypt.hashSync(password, 10); - const emailUser = await User.findOne({ email: email }); - if (emailUser) { - return res - .status(500) - .json({ status: "fail", error: "email already exists" }); - } - - try { - newUser.password = await newUser.encryptPassword(password); - await newUser.save(); - - res.json({ - status: "ok", - msg: "Usuario creado", + const newUser = new User({ + name: name, + email: email, + password: password, }); - } catch (error) { + + const emailUser = await User.findOne({ email: email }); + if (emailUser) { + return res + .status(500) + .json({ status: "fail", error: "email already exists" }); + } + + try { + newUser.password = await newUser.encryptPassword(password); + await newUser.save(); + + res.json({ + status: "ok", + msg: "Usuario creado", + }); + } catch (error) { + return res + .status(500) + .json({ status: "fail", error: `internal error:${error}` }); + } + }); +} + +else{ + + router.post("/register", (req, res) => { return res - .status(500) - .json({ status: "fail", error: `internal error:${error}` }); - } -}); + .status(500) + .json({ status: "faill", error: `No tiene permitido crear usuarios nuevos` }); + + + }) + +} router.post("/login", async (req, res) => { const { email, password } = req.body; var user = await User.findOne({ email: email }); if (!user) { - res.status(401).json({ status: "fail", error: "Invalid credentials email" }); + res + .status(401) + .json({ status: "fail", error: "Invalid credentials email" }); return; } - - if (! await user.matchPassword(password)) { - return res.status(401).json({ status: "fail", error: "Invalid credentials pass" }); - + + if (!(await user.matchPassword(password))) { + return res + .status(401) + .json({ status: "fail", error: "Invalid credentials pass" }); } user.set("password", undefined, { strict: false }); const token = jwt.sign(