feat: refs #5144 saveTable

This commit is contained in:
Alex Moreno 2024-04-10 13:01:49 +02:00
parent 97b778245f
commit 2a7fa0eaef
1 changed files with 18 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import con from '../db/connect.js';
import conMaster from '../db/connectMaster.js';
import fs from 'node:fs';
export default async uniqueRead => {
const reads = new Set([
@ -70,7 +71,23 @@ export default async uniqueRead => {
uniqueRead[3].size,
]
);
await saveTable();
} catch (e) {
console.log('LIADA', palletFk, e);
console.log('error debugging', palletFk, e);
}
};
async function saveTable() {
const [table] = await con.query(`SELECT * FROM trys WHERE DATE(timestamp) = CURDATE()`);
const date = new Date().toISOString().split('T')[0];
if (!table.length) return;
const file = fs.createWriteStream(`${date}.txt`);
file.on('error', function(err) {
console.error(err);
});
table.forEach(function(v) {
file.write(JSON.stringify(v) + '\n');
});
file.end();
}