2018-12-21 00:13:51 +00:00
|
|
|
import {Connection} from "mysql";
|
2024-02-29 13:15:31 +00:00
|
|
|
import {sqliteConnection as con} from "../index";
|
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
|
2018-12-20 21:30:16 +00:00
|
|
|
interface RespuestaDatos {
|
|
|
|
estudio: string,
|
|
|
|
eps: number,
|
|
|
|
alAire: string,
|
|
|
|
temporada: string,
|
|
|
|
anio: number,
|
|
|
|
fuente: string,
|
|
|
|
generos: string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface RespuestaOP {
|
|
|
|
OP_ID: number,
|
|
|
|
anime_ID: number,
|
|
|
|
num_OP: number,
|
|
|
|
nombre: string,
|
|
|
|
artista: string,
|
|
|
|
eps: string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface RespuestaED {
|
|
|
|
ED_ID: number,
|
|
|
|
anime_ID: number,
|
|
|
|
num_ED: number,
|
|
|
|
nombre: string,
|
|
|
|
artista: string,
|
|
|
|
eps: string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Respuesta extends RespuestaDatos {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const GestorDeTareas = require("../GestorDeTareas/GestorDeTareas").GestorDeTareas;
|
|
|
|
const YAML = require('yaml');
|
|
|
|
|
|
|
|
const obtenerDatos = (req: any, res: any) => {
|
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
const anime_ID = req.params.anime_ID;
|
2018-12-20 21:30:16 +00:00
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
const respuesta: any = {};
|
|
|
|
const gestor = new GestorDeTareas(() => {
|
|
|
|
console.log(YAML.stringify(respuesta));
|
|
|
|
res.send(YAML.stringify(respuesta));
|
|
|
|
});
|
2018-12-20 21:30:16 +00:00
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
const query1 = `SELECT estudio, eps, alAire, temporada, anio, fuente, generos FROM animes WHERE anime_ID=${anime_ID}`;
|
|
|
|
gestor.agregarTarea();
|
2024-02-29 13:15:31 +00:00
|
|
|
con.query(query1, (err, res: RespuestaDatos[]) => {
|
2018-12-21 00:13:51 +00:00
|
|
|
if (!err) {
|
2018-12-20 21:30:16 +00:00
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
const data = res[0];
|
2018-12-20 21:30:16 +00:00
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
respuesta.estudio = data.estudio;
|
|
|
|
respuesta.eps = data.estudio;
|
|
|
|
respuesta.alAire = data.alAire;
|
|
|
|
respuesta.temporada = data.temporada;
|
|
|
|
respuesta.anio = data.anio;
|
|
|
|
respuesta.fuente = data.fuente;
|
|
|
|
respuesta.generos = data.generos;
|
2018-12-20 21:30:16 +00:00
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
gestor.terminarTarea();
|
2018-12-20 21:30:16 +00:00
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
} else {
|
|
|
|
respuesta.error = true;
|
|
|
|
console.log(`Error al ejecutar sentencia SQL en /Anime/obtenerDatos (con.query)(1):\n${query1}\n${err}`);
|
|
|
|
}
|
|
|
|
});
|
2018-12-20 21:30:16 +00:00
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
const query2 = `SELECT * FROM OP WHERE anime_ID=${anime_ID}`;
|
|
|
|
gestor.agregarTarea();
|
2024-02-29 13:15:31 +00:00
|
|
|
con.query(query2, (err, res: RespuestaOP[]) => {
|
2018-12-21 00:13:51 +00:00
|
|
|
if (!err) {
|
2018-12-20 21:30:16 +00:00
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
const ops: any = {};
|
|
|
|
for (const op of res) {
|
|
|
|
ops[op.num_OP] = {
|
|
|
|
nombre: op.nombre,
|
|
|
|
artista: op.artista,
|
|
|
|
eps: op.eps
|
2018-12-20 21:30:16 +00:00
|
|
|
}
|
2018-12-21 00:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
respuesta.OP = ops;
|
|
|
|
gestor.terminarTarea();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
respuesta.error = true;
|
|
|
|
console.log(`Error al ejecutar sentencia SQL en /Anime/obtenerDatos (con.query)(2):\n${query2}\n${err}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const query3 = `SELECT * FROM ED WHERE anime_ID=${anime_ID}`;
|
|
|
|
gestor.agregarTarea();
|
2024-02-29 13:15:31 +00:00
|
|
|
con.query(query3, (err, res: RespuestaED[]) => {
|
2018-12-21 00:13:51 +00:00
|
|
|
if (!err) {
|
|
|
|
|
|
|
|
const eds: any = {};
|
|
|
|
for (const ed of res) {
|
|
|
|
eds[ed.num_ED] = {
|
|
|
|
nombre: ed.nombre,
|
|
|
|
artista: ed.artista,
|
|
|
|
eps: ed.eps
|
2018-12-20 21:30:16 +00:00
|
|
|
}
|
2018-12-21 00:13:51 +00:00
|
|
|
}
|
2018-12-20 21:30:16 +00:00
|
|
|
|
2018-12-21 00:13:51 +00:00
|
|
|
respuesta.ED = eds;
|
|
|
|
gestor.terminarTarea();
|
2018-12-20 21:30:16 +00:00
|
|
|
|
|
|
|
} else {
|
2018-12-21 00:13:51 +00:00
|
|
|
respuesta.error = true;
|
|
|
|
console.log(`Error al ejecutar sentencia SQL en /Anime/obtenerDatos (con.query)(3):\n${query3}\n${err}`);
|
2018-12-20 21:30:16 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.obtenerDatos = obtenerDatos;
|