Es una aplicación que se utiliza para realizar las actualizaciones de los dispositivos fabricados en FANIOT a través de OTA.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
1.1 KiB

//Se declara express
const express = require("express");
//Se inicializa express
var app = express();
//Conexión MariaDB
const pool = require('../../db')
const response = require("../../network/response");
async function addFirmware(firmware) {
//const conn = await pool.getConnection();
try{
const rows = await pool.query(`INSERT INTO main_database.firmwares (product_id, firmware_version, etiqueta, filepath) VALUES ('${firmware.productID}', '${firmware.version}', '${firmware.label}', '${firmware.filepath}') RETURNING firmware_id`);
const newFirmware = rows[0].firmware_id;
console.log(newFirmware)
const updateDevices = await pool.query(`UPDATE main_database.devices SET firmware_id_update = ${newFirmware} WHERE product_id = ${firmware.productID}`);
console.log(updateDevices)
return rows;
}catch(err){
return err.code;
}
}
async function getFirmwares() {
return new Promise(async (resolve, reject) => {
//const conn = await pool.getConnection();
const rows = await pool.query(`SELECT * FROM main_database.firmwares`);
resolve(rows);
});
}
module.exports = {
add: addFirmware,
list: getFirmwares,
};