From e61f36a586896f08ceb8c156731d60477c5bca70 Mon Sep 17 00:00:00 2001 From: underdorff18 Date: Sun, 20 Nov 2022 16:47:17 -0500 Subject: [PATCH] Added functionality to update files --- JS/1000.xlsx | Bin 5203 -> 5203 bytes JS/dbtools.js | 11 +++++++++++ JS/excelreader.js | 10 +++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/JS/1000.xlsx b/JS/1000.xlsx index 374e1e392295b8cbbbf00ae26c7d717542ef9025..14f05c9ec295ceeb7c77c3843b8eb12d72e69e9f 100644 GIT binary patch delta 2342 zcmY*bc{r49A04|fh_RI=&De&qJob@KzQ`C62HDr_*)>s$$66!GGJMt;F)ECC?Q3Pr zmlDY`)(?@Tl)Q;z@Frc?`@Q#H=Q@A7(O)X6ac%ty$Hg_-3SB6+amz?3YbMC8TH+6BgrgjI2Ndy4z9fljU4-P&m(s12F# zjC{3aT-k$o6&Da7NOVcX$?Gf5tPd8X!RUC=u+-c+uhpXDaQ)lQ*yIpyHU`89NNgpg z!0-M{RM8!HCQ_5{#5^DX%R}-QUjJev3+;-)zib~0#eB6o*Wz?)`sFt0PQ;Y+JEWj2 zpma8(G`ByQ2G4)Y^-1U%?3gJbo@#s3QIP)J?C!Ef)HV6LWtPaX1YDU+!@hDzdx6_l z9(En^ALNfrUr8oR!s}1+r8|K-tsd^3k`w{!@??fAuqlHz%jPw^ze z^1=;|x$Kl~h;{m#`WY}o+O-vZ5b*>!p*62^-n`=56h0Xf6zevSUNIN=#lmDm?>*}S z$0hGCCWW@~(M*UruLik&S+c!Q`er($`v&}@s8#9SJpk?>KlQP(#mCYs(tJC96q4J6 z@}0Dd4L7jekOEv=r(g6zth~y5?f{L1^_%o$v(I)N#TT5HFMvdX2!b8?quV2Z;hqy& ziXFH?5N^q)6lxypb|s1ks5Ki7OSi$KLT>dZSl5P1untMdk5|ck3ac5x>jxRSSAWi7 z3O=ZItgDe@cXUx;Qecqnmh(qG##w^$Vm?eu{EE{nXG?*nx zd8CIx8$2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5ZPhNOf@wi z+B3_6(Lgak0{J9UZp(i{*a)DmO4<}_;pj=OwfO-|d|c?cAe6=x+nkUe!j~TK>gQ*+ zP5TtQ&DAR}oe-;gnUT^s52=6h`uh}bji}+h8;NBV{LlsEz0JeafCHWIEVoT@KV^E) z@c%NAjJZ&N1x*P`|AbGF8F^+#G0rMd<7ExH2Z{iQBVAO(-jiI{zwNi|s3Vs& z6sOwj5cSnHB0`%S?qVs`UlxM~4AVIC2bByJDeJ$e=re`NEdKQ4wV!nSaV*Q9vO*2! z&ioTCF!-_G6$J~&{01>_4c3DqbC66V8vMlXEfcQ+=fSr4zyE+_&wK3f!RDWoANc=& YlSwM(75jDT;4P#+UiII%pnTZ>0Ik|Lj{pDw diff --git a/JS/dbtools.js b/JS/dbtools.js index f7c0bd4..b02154b 100644 --- a/JS/dbtools.js +++ b/JS/dbtools.js @@ -11,6 +11,17 @@ const dbtools = { const result = await this.collection.insertOne(system); console.log(`Created a system entry with id: ${result.insertedId}`); }, + updateSystem: async function (system) { + console.log(system); + const result = await this.collection.replaceOne({ serialnum: system.serialnum }, { + serialnum: system.serialnum, + model: system.model, + OS: system.OS, + price: system.price, + specs: system.specs + }); + console.log(`${result.deletedCount} document(s) was/were updated.`); + }, deleteSystem: async function (serial) { const result = await this.collection.deleteOne({ serialnum: serial}); console.log(`${result.deletedCount} document(s) was/were deleted.`); diff --git a/JS/excelreader.js b/JS/excelreader.js index 3c580bb..a64c251 100644 --- a/JS/excelreader.js +++ b/JS/excelreader.js @@ -1,7 +1,7 @@ const fs = require('fs'); const Path = require('path'); const { MongoClient, ServerApiVersion } = require('mongodb'); -dbtools = require('./dbtools'); +const dbtools = require('./dbtools'); const xlsx = require('xlsx'); const chokidar = require('chokidar'); const System = require('./system'); @@ -25,7 +25,11 @@ function readInventoryFile(filepath) { } -var inventoryWatcher = chokidar.watch(Path.join(__dirname, "Inventory"), {ignored: /^\./, persistent: true}); +var inventoryWatcher = chokidar.watch(Path.join(__dirname, "Inventory"), { + ignored: /(^|[\/\\])\../, + persistent: true, + awaitWriteFinish: true, +}); console.log(`Watching directory for changes...` ) inventoryWatcher @@ -33,7 +37,7 @@ inventoryWatcher dbtools.insertSystem(readInventoryFile(filepath)); }) .on('change', function(filepath) { - console.log('File', path, 'has been changed'); + dbtools.updateSystem(readInventoryFile(filepath)); }) .on('unlink', function(filepath) { dbtools.deleteSystem(parseInt(Path.basename(filepath, '.xlsx')));