
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 };