From 2a7fa0eaefb6e3c94a03b4905750a00e97eaa841 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 10 Apr 2024 13:01:49 +0200 Subject: [PATCH] feat: refs #5144 saveTable --- util/debugMissing.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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(); +}