Skip to content

Commit

Permalink
remove redundant collection parameter in dbtools functions
Browse files Browse the repository at this point in the history
  • Loading branch information
underdorff18 committed Nov 11, 2022
1 parent c87b217 commit d90af6b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions JS/dbtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ client.connect();

const dbtools = {
collection: client.db('inventorydb').collection('systems'),
insertSystem: async function (collection, system) {
const result = await collection.insertOne(system);
insertSystem: async function (system) {
const result = await this.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});
deleteSystem: async function (serial) {
const result = await this.collection.deleteOne({ serialnum: serial});
console.log(`${result.deletedCount} document(s) was/were deleted.`);
},
getAllSystems: async function (collection) {
cursor = await collection.find();
getAllSystems: async function () {
cursor = await this.collection.find();
let allSystems = []
await cursor.forEach( function (result) {allSystems.push(result);});
return allSystems;
Expand Down
4 changes: 2 additions & 2 deletions JS/excelreader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ console.log(`Watching directory for changes...` )

inventoryWatcher
.on('add', function(filepath) {
dbtools.insertSystem(dbtools.collection, readInventoryFile(filepath));
dbtools.insertSystem(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')));
dbtools.deleteSystem(parseInt(Path.basename(filepath, '.xlsx')));
})
.on('error', function(error) {
console.error('Error happened', error);
Expand Down
2 changes: 1 addition & 1 deletion JS/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ app.get('/', (req, res) => {
});

app.get('/systems', async function(req, res) {
result = await dbtools.getAllSystems(dbtools.collection);
result = await dbtools.getAllSystems();
console.log(result);
res.send(result);

Expand Down

0 comments on commit d90af6b

Please sign in to comment.