diff --git a/README.md b/README.md index a4b2ab6..a91dc8d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/server/data/memo-dao.js b/src/server/data/memo-dao.js new file mode 100644 index 0000000..1434f7a --- /dev/null +++ b/src/server/data/memo-dao.js @@ -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)) { + 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 };