diff --git a/util/debugMissing.js b/util/debugMissing.js index 6b5dbc7..51d2f4c 100644 --- a/util/debugMissing.js +++ b/util/debugMissing.js @@ -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(); +}