Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a07897bbee9a4866a9f9d2b26ba9c652)](https://www.codacy.com/manual/Codacy-ACME/nodeproject?utm_source=github.com&utm_medium=referral&utm_content=codacy-acme/nodeproject&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/a07897bbee9a4866a9f9d2b26ba9c652)](https://www.codacy.com/manual/Codacy-ACME/nodeproject?utm_source=github.com&utm_medium=referral&utm_content=codacy-acme/nodeproject&utm_campaign=Badge_Coverage)
# nodeproject
### this is an issue
######## orly?!
## the description of this project
39 changes: 39 additions & 0 deletions src/server/data/memo-dao.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* The MemosDAO must be constructed with a connected database object */
function MemosDAO(db) {

"use strict";

/* If this constructor is called without the "new" operator, "this" points
* to the global object. Log a warning and call it correctly. */
if (false === (this instanceof MemosDAO)) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Unnecessary parentheses around expression.

Suggested change
if (false === (this instanceof MemosDAO)) {
if (false === this instanceof MemosDAO) {

console.log("Warning: MemosDAO constructor called without 'new' operator");
return new MemosDAO(db);
}

const memosCol = db.collection("memos");

this.insert = (memo, callback) => {

// Create allocations document
const memos = {
memo,
timestamp: new Date()
};

memosCol.insert(memos, (err, result) => !err ? callback(null, result) : callback(err, null));
};

this.getAllMemos = (callback) => {

memosCol.find({}).sort({
timestamp: -1
}).toArray((err, memos) => {
if (err) return callback(err, null);
if (!memos) return callback("ERROR: No memos found", null);
callback(null, memos);
});
};

}

module.exports = { MemosDAO };