-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bc7774
commit 4fa588e
Showing
6 changed files
with
65 additions
and
35 deletions.
There are no files selected for viewing
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { MongoClient, ServerApiVersion } = require('mongodb'); | ||
|
||
const uri = 'mongodb+srv://nickoverdorff:[email protected]/?retryWrites=true&w=majority'; | ||
const client = new MongoClient(uri); | ||
|
||
client.connect(); | ||
|
||
const dbtools = { | ||
collection: client.db('inventorydb').collection('systems'), | ||
insertSystem: async function (collection, system) { | ||
const result = await collection.insertOne(system); | ||
console.log(`Created a system entry with id: ${result.insertedId}`); | ||
}, | ||
deleteSystem: async function (collection, serial) { | ||
const result = await collection.deleteOne({ serialnum: serial}); | ||
console.log(`${result.deletedCount} document(s) was/were deleted.`); | ||
}, | ||
getAllSystems: async function (collection) { | ||
cursor = await collection.find(); | ||
let allSystems = [] | ||
await cursor.forEach( function (result) {allSystems.push(result);}); | ||
return allSystems; | ||
} | ||
} | ||
|
||
module.exports = dbtools; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,43 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Path = require('path'); | ||
const { MongoClient, ServerApiVersion } = require('mongodb'); | ||
dbtools = require('./dbtools'); | ||
const xlsx = require('xlsx'); | ||
const chokidar = require('chokidar'); | ||
const System = require('./system'); | ||
const { all } = require('express/lib/application'); | ||
|
||
const myfilepath = path.join(__dirname, 'Inventory', 'samplepc1234.xlsx'); | ||
//const myfilepath = Path.join(__dirname, 'Inventory', 'samplepc1234.xlsx'); | ||
|
||
function readInventoryFile(filepath) { | ||
let workbook = xlsx.readFileSync(filepath); | ||
let sheetNames = workbook.SheetNames; | ||
let sheetData = workbook.Sheets[sheetNames[0]]; | ||
|
||
//Here is where we use known cell locations of the specs needed to build the systems file | ||
let serialNum = sheetData.D1.v; | ||
let serialnum = sheetData.D1.v; | ||
let model = sheetData.D2.v; | ||
let OS = sheetData.D3.v; | ||
let price = sheetData.D4.v; | ||
let specs = [sheetData.D5.v, sheetData.D6.v, sheetData.D7.v, sheetData.D8.v]; | ||
|
||
return new System(serialNum, model, OS, price, specs); | ||
return new System(serialnum, model, OS, price, specs); | ||
} | ||
|
||
|
||
console.log(readInventoryFile(myfilepath)); | ||
|
||
var inventoryWatcher = chokidar.watch(path.join(__dirname, "Inventory"), {ignored: /^\./, persistent: true}); | ||
|
||
// inventoryWatcher | ||
// .on('add', function(path) { | ||
// fs.appendFile('systems.json', ', ') | ||
// }) | ||
// | ||
var inventoryWatcher = chokidar.watch(Path.join(__dirname, "Inventory"), {ignored: /^\./, persistent: true}); | ||
console.log(`Watching directory for changes...` ) | ||
|
||
inventoryWatcher | ||
.on('add', function(filepath) { | ||
dbtools.insertSystem(dbtools.collection, readInventoryFile(filepath)); | ||
}) | ||
.on('change', function(filepath) { | ||
console.log('File', path, 'has been changed'); | ||
}) | ||
.on('unlink', function(filepath) { | ||
dbtools.deleteSystem(dbtools.collection, parseInt(Path.basename(filepath, '.xlsx'))); | ||
}) | ||
.on('error', function(error) { | ||
console.error('Error happened', error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.