EOD 14/09/2022

This commit is contained in:
Ciro-pro
2022-09-14 21:40:05 -03:00
parent e23cf74cde
commit a36704b80e
7 changed files with 288 additions and 0 deletions

2
.env Normal file
View File

@@ -0,0 +1,2 @@
ACCESS_TOKEN_SECRET=febb08c101e3de877935df7b4827a4f2fe0808f30135c689fd45a79abe8f65ebadf42f477e9d36564a9090b66a7051254bf0bfa4d2678b7ed43bb6e13ea44582
REFRESH_TOKEN_SECRET=1c99f24219da67627db6300cd9916c6814af22a01e585f0e19a12f895906e42d222e4d25f3c35662e8b82ea94756d5e4f55bd0a322b3e335cda1a2b2de29d6e1

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules/

View File

@@ -0,0 +1,165 @@
const db = require("../models");
const CandadoActivo = db.candadoActivos;
const Op = db.Sequelize.Op;
// Create and Save a new Candado
exports.create = (req, res) => {
// Validate request
if (!req.body.codigo) {
console.log("body: ", req.body);
res.status(400).send({
message: "Content can not be empty!",
});
return;
}
// Create a Candado
const candado = {
codigo: req.body.codigo,
rut: req.body.rut,
bloqueo_id: req.body.bloqueo_id,
fecha_inicio: req.body.fecha_inicio,
fecha_fin: req.body.fecha_fin,
};
// Save Candado in the database
CandadoActivo.create(candado)
.then((data) => {
res.send(data);
})
.catch((err) => {
res.status(500).send({
message:
err.message ||
"Some error occurred while creating the CandadoActivo.",
});
});
};
// Retrieve all Candados from the database.
exports.findAll = (req, res) => {
const title = req.query.title;
var condition = title ? { title: { [Op.like]: `%${title}%` } } : null;
CandadoActivo.findAll({ where: condition })
.then((data) => {
res.send(data);
})
.catch((err) => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving Candados.",
});
});
};
// Find a single Candado with an id
exports.findOne = (req, res) => {
const id = req.params.id;
CandadoActivo.findByPk(id)
.then((data) => {
if (data) {
res.send(data);
} else {
res.status(404).send({
message: `Cannot find Candado with id=${id}.`,
});
}
})
.catch((err) => {
res.status(500).send({
message: "Error retrieving Candado with id=" + id,
});
});
};
// Update a Candado by the id in the request
exports.update = (req, res) => {
const id = req.params.id;
CandadoActivo.update(req.body, {
where: { id: id },
})
.then((num) => {
if (num == 1) {
res.send({
message: "Candado was updated successfully.",
});
} else {
res.send({
message: `Cannot update Candado with id=${id}. Maybe Candado was not found or req.body is empty!`,
});
}
})
.catch((err) => {
res.status(500).send({
message: "Error updating Candado with id=" + id,
});
});
};
// Delete a Candado with the specified id in the request
exports.delete = (req, res) => {
const id = req.params.id;
CandadoActivo.destroy({
where: { id: id },
})
.then((num) => {
if (num == 1) {
res.send({
message: "Candado was deleted successfully!",
});
} else {
res.send({
message: `Cannot delete Candado with id=${id}. Maybe Candado was not found!`,
});
}
})
.catch((err) => {
res.status(500).send({
message: "Could not delete Candado with id=" + id,
});
});
};
// Delete all Candados from the database.
exports.deleteAll = (req, res) => {
CandadoActivo.destroy({
where: {},
truncate: false,
})
.then((nums) => {
res.send({ message: `${nums} Candado were deleted successfully!` });
})
.catch((err) => {
res.status(500).send({
message:
err.message || "Some error occurred while removing all Candados.",
});
});
};
// Find all by ID Candados
exports.findAllByBloqueo = (req, res) => {
const bloqueo = req.params.bloqueo;
CandadoActivo.findAll({ where: { bloqueo_id: bloqueo } })
.then((data) => {
res.send(data);
})
.catch((err) => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving Candados.",
});
});
};
// Find all by ID Candados
exports.findAllByRut = (req, res) => {
const rut = req.params.rut;
CandadoActivo.findAll({ where: { rut } })
.then((data) => {
res.send(data);
})
.catch((err) => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving Candados.",
});
});
};

View File

@@ -0,0 +1,42 @@
module.exports = (sequelize, Sequelize) => {
const CandadoActivo = sequelize.define(
"candadoActivo",
{
id: {
type: Sequelize.INTEGER,
allowNull: false,
},
codigo: {
type: Sequelize.STRING,
allowNull: false,
},
rut: {
type: Sequelize.STRING,
allowNull: false,
},
bloqueo_id: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
},
fecha_inicio: {
type: Sequelize.DATE,
allowNull: false,
},
fecha_fin: {
type: Sequelize.DATE,
allowNull: true,
},
},
{
indexes: [
// Create a unique index on email
{
unique: true,
fields: ["id", "bloqueo_id"],
},
],
}
);
return CandadoActivo;
};

View File

@@ -0,0 +1,27 @@
const proxy = require("../controllers/proxis");
module.exports = (app) => {
const candadosActivos = require("../controllers/candadoActivo.controller.js");
var router = require("express").Router();
// Create a new bloqueo
router.post("/", proxy.authenticateUser, candados.create);
// Retrieve all bloqueos
router.get("/", proxy.authenticateUser, candados.findAll);
// Retrieve all published bloqueos
router.get(
"/byBloqueo/:bloqueo",
proxy.authenticateUser,
candados.findAllByBloqueo
);
// Retrieve all published bloqueos
router.get("/byRut/:rut", proxy.authenticateUser, candados.findAllByRut);
// Retrieve a single bloqueo with id
router.get("/:id", proxy.authenticateUser, candados.findOne);
// Update a bloqueo with id
router.put("/:id", proxy.authenticateUser, candados.update);
// Delete a bloqueo with id
router.delete("/:id", proxy.authenticateUser, candados.delete);
// Delete all bloqueos
router.delete("/", proxy.authenticateUser, candados.deleteAll);
app.use("/api/candadosActivos", router);
};

4
app/routes/todo Normal file
View File

@@ -0,0 +1,4 @@
Completar candadoActivo
Crear trabajadorActivo
Crear ruta de getBloqueoConfig
Instalar y probar en cloud con HTTPS

View File

@@ -47,3 +47,50 @@ Content-Type: application/json
###
GET http://localhost:8000/api/equipos
Authorization: BEARER eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imp1YW5AdGVzdC5jb20iLCJpYXQiOjE2NjE4MTMyOTN9._xo3eCA6NDsKKjCJ1n6YBO6xM0RyHxXuLfP6HK604q4
###
DELETE http://localhost:8000/api/equipos/5
Authorization: BEARER eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imp1YW5AdGVzdC5jb20iLCJpYXQiOjE2NjE4MTMyOTN9._xo3eCA6NDsKKjCJ1n6YBO6xM0RyHxXuLfP6HK604q4
###
DELETE http://localhost:8000/api/equipos
Authorization: BEARER eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imp1YW5AdGVzdC5jb20iLCJpYXQiOjE2NjE4MTMyOTN9._xo3eCA6NDsKKjCJ1n6YBO6xM0RyHxXuLfP6HK604q4
###
PUT http://localhost:8000/api/equipos/6
Authorization: BEARER eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imp1YW5AdGVzdC5jb20iLCJpYXQiOjE2NjE4MTMyOTN9._xo3eCA6NDsKKjCJ1n6YBO6xM0RyHxXuLfP6HK604q4
Content-Type: application/json
{
"id": 6,
"descripcion": "EQ-PE-002",
"ubicacion": "Planta pelo"
}
###
POST http://localhost:8000/api/equipos
Authorization: BEARER eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imp1YW5AdGVzdC5jb20iLCJpYXQiOjE2NjE4MTMyOTN9._xo3eCA6NDsKKjCJ1n6YBO6xM0RyHxXuLfP6HK604q4
Content-Type: application/json
{
"tag": "EQ-PE-010",
"descripcion": "Equipo 010 Planta 01",
"ubicacion": "Planta 01",
"bloqueo_id": 0
}
## CANDADOS
###
GET http://localhost:8000/api/candados
Authorization: BEARER eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imp1YW5AdGVzdC5jb20iLCJpYXQiOjE2NjE4MTMyOTN9._xo3eCA6NDsKKjCJ1n6YBO6xM0RyHxXuLfP6HK604q4
###
PUT http://localhost:8000/api/candados/186
Authorization: BEARER eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imp1YW5AdGVzdC5jb20iLCJpYXQiOjE2NjE4MTMyOTN9._xo3eCA6NDsKKjCJ1n6YBO6xM0RyHxXuLfP6HK604q4
Content-Type: application/json
{
"codigo": "CDD-04",
"id": "186",
"rut": "11432448-5"
}