first commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
|
||||
const connectDb = require("./db");
|
||||
|
||||
const save = async (newDocument) => {
|
||||
const db = await connectDb();
|
||||
if (!db) {
|
||||
throw new Error('Database not connected');
|
||||
}
|
||||
|
||||
const collection = db.collection("Favorites");
|
||||
let result = await collection.insertOne(newDocument);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const getAll = async () => {
|
||||
const db = await connectDb();
|
||||
if (!db) {
|
||||
throw new Error('Database not connected');
|
||||
}
|
||||
const collection = db.collection("Favorites");
|
||||
let result = await collection.find({}).toArray();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = { save, getAll };
|
||||
Reference in New Issue
Block a user