Skip to content

Commit

Permalink
Merge branch 'matias' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiasBais committed Apr 8, 2024
2 parents 5606b79 + 0dc20ae commit 8334681
Show file tree
Hide file tree
Showing 25 changed files with 484 additions and 673 deletions.
14 changes: 7 additions & 7 deletions api/v1/categoria.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as express from "express";
import {
Etiqueta,
Categoria,
} from "./model.js";
import { mensajeError401, mensajeError403, mensajeError404 } from "./mensajesError.js";
Etiqueta,
Categoria,
} from "./model.js";
import { mensajeError401, mensajeError403, mensajeError404 } from "./mensajesError.js";


const router = express.Router();
Expand Down Expand Up @@ -67,8 +67,8 @@ router.post("/", async (req, res) => {
res.status(400).send(error.message);
}
});
// Ruta para actualizar una categoría por su ID

// Ruta para actualizar una categoría por su ID
router.patch("/:id", async (req, res) => {
if (req.session.usuario.perfil.permiso.ID < 3) {
res.status(401).send(mensajeError401);
Expand Down Expand Up @@ -106,7 +106,7 @@ router.delete("/:id", async (req, res) => {
res.status(500).send(error.message);
}
});




Expand Down
5 changes: 4 additions & 1 deletion api/v1/etiqueta.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ router.delete("/:etiquetaID/suscripcion", function (req, res) {
});

router.get("/masUsadas", function (req, res) {

if (req.session.usuario.perfil.permiso.ID < 3) {
res.status(401).send(mensajeError401);
return;
}

EtiquetasPregunta.findAll({
attributes: ["etiquetumID", [Sequelize.fn('COUNT', Sequelize.col('etiquetumID')), 'cantidad']],
Expand Down
3 changes: 2 additions & 1 deletion api/v1/ia.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ async function moderar(post) {
try {
const response = await fetch(`${base_url}/chat/completions`, requestOptions);
const responseData = await response.json();
return JSON.parse(responseData.choices[0].message.content);
const contenido=responseData.choices[0].message.content;
return JSON.parse(contenido);
} catch (error) {
throw error;
}
Expand Down
31 changes: 17 additions & 14 deletions api/v1/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,10 @@ Pregunta.pagina = ({ pagina = 0, duenioID: duenioDNI, filtrar, formatoCorto, usu
`match(titulo) against (:where_titulo IN BOOLEAN MODE)`
)
)
let valorAgainstMatch=`${filtrar.texto}*`;
opciones.replacements={
where_cuerpo:valorAgainstMatch
,where_titulo:valorAgainstMatch
let valorAgainstMatch = `${filtrar.texto}*`;
opciones.replacements = {
where_cuerpo: valorAgainstMatch
, where_titulo: valorAgainstMatch
};
filtrarTexto = true;
}
Expand Down Expand Up @@ -721,12 +721,12 @@ Pregunta.pagina = ({ pagina = 0, duenioID: duenioDNI, filtrar, formatoCorto, usu
}
}
);
if(!opciones.replacements)
opciones.replacements={};
let variablesEnConsulta=filtrar.etiquetas.map(eti=>{
let nombreVariable='eti_'+eti
opciones.replacements[nombreVariable]=eti;
return ':'+nombreVariable;
if (!opciones.replacements)
opciones.replacements = {};
let variablesEnConsulta = filtrar.etiquetas.map(eti => {
let nombreVariable = 'eti_' + eti
opciones.replacements[nombreVariable] = eti;
return ':' + nombreVariable;
});
opciones.attributes.include.push(
[
Expand Down Expand Up @@ -762,8 +762,8 @@ Pregunta.pagina = ({ pagina = 0, duenioID: duenioDNI, filtrar, formatoCorto, usu
if (filtrarTexto) {
ranking.push(`(match(post.cuerpo) against (:order_cuerpo IN BOOLEAN MODE) + match(titulo) against (:order_titulo IN BOOLEAN MODE)*2)`);
// * En la definición del where se establece replacements con un par de el mismo valor.
opciones.replacements['order_cuerpo']=
opciones.replacements['order_titulo']=
opciones.replacements['order_cuerpo'] =
opciones.replacements['order_titulo'] =
opciones.replacements['where_cuerpo']
}
if (filtrarEtiquetas) {
Expand Down Expand Up @@ -851,6 +851,7 @@ Post.pagina = ({ pagina = 0, DNI } = {}) => {
include: [
{
model: Post,
where: { eliminadorDNI: { [Sequelize.Op.is]: null } },
include: [
{
model: Usuario,
Expand Down Expand Up @@ -881,6 +882,7 @@ Post.pagina = ({ pagina = 0, DNI } = {}) => {
required: false,
include: {
model: Post,
where: { eliminadorDNI: { [Sequelize.Op.is]: null } },
include: [
{
model: Usuario,
Expand Down Expand Up @@ -944,6 +946,7 @@ Respuesta.pagina = ({ pagina = 0, DNI } = {}) => {
include: [
{
model: Post,
where: { eliminadorDNI: { [Sequelize.Op.is]: null } },
include: [
{
model: Voto
Expand All @@ -967,6 +970,7 @@ Respuesta.pagina = ({ pagina = 0, DNI } = {}) => {
required: true,
include: {
model: Post,
where: { eliminadorDNI: { [Sequelize.Op.is]: null } },
include: [
{
model: Usuario,
Expand Down Expand Up @@ -1004,7 +1008,7 @@ Respuesta.pagina = ({ pagina = 0, DNI } = {}) => {
fecha_baja: null, // * Vigentes
}
, required: false
,separate: true
, separate: true
}
],
attributes: {
Expand Down Expand Up @@ -1252,7 +1256,6 @@ Parametro.findAll().then((parametros) => {
});
});


export {
Parametro,
Carrera,
Expand Down
50 changes: 22 additions & 28 deletions api/v1/parametro.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Parametro,
} from "./model.js";

import {setModera, setRechazaPost, setReportaPost, setResultadosPorPagina} from "./parametros.js"
import { setModera, setRechazaPost, setReportaPost, setResultadosPorPagina } from "./parametros.js"
import { mensajeError401 } from "./mensajesError.js";

const router = express.Router();
Expand All @@ -27,43 +27,37 @@ Parametro.findAll().then((ps) => {


router.get("/", function (req, res) {
if (req.session.usuario.perfil.permiso.ID < 3) {
res.status(401).send(mensajeError401);
return;
}
Parametro.findAll({
attributes: ["ID", "descripcion", "valor"]
}).then((parametros) => {
res.send(parametros);
});

router.patch("/:ID", function (req, res) {
if (req.session.usuario.perfil.permiso.ID < 3) {
res.status(401).send(mensajeError401);
return;
}
if (!req.session.usuario) {
res
.status(403)
.send("No se poseen permisos de administración o sesión válida activa");
return;
} else if (req.session.usuario.perfil.permiso.ID < 3) {
res
.status(403)
.send("No se poseen permisos de administración o sesión válida activa");
return;
}
Parametro.findByPk(req.params.ID).then((p) => {
p.valor = req.body.valor;
p.save();
res.status(200).send(p);
if (req.params.ID == 1)
setResultadosPorPagina(parseInt(req.body.valor));
if (req.params.ID == 2) setModera(req.body.valor == "1");
if (req.params.ID == 3) setRechazaPost(parseInt(req.body.valor));
if (req.params.ID == 4) setReportaPost(parseInt(req.body.valor));
});
});

router.patch("/:ID", function (req, res) {
if (req.session.usuario.perfil.permiso.ID < 3) {
res.status(401).send(mensajeError401);
return;
}
Parametro.findByPk(req.params.ID).then((p) => {
p.valor = req.body.valor;
p.save();
res.status(200).send(p);
if (req.params.ID == 1)
setResultadosPorPagina(parseInt(req.body.valor));
if (req.params.ID == 2) setModera(req.body.valor == "1");
if (req.params.ID == 3) setRechazaPost(parseInt(req.body.valor));
if (req.params.ID == 4) setReportaPost(parseInt(req.body.valor));
});
});






export { router };
Loading

0 comments on commit 8334681

Please sign in to comment.