module.exports = {
    insertTodayDomains : function (db, domains){
        return new Promise((resolve,reject)=>{
            db.collection('today').insert(domains, ()=>{
                resolve();
            });
        });
    },

    getYesterdayDomains : function (db){
        return getArrayFromDatabase(db, 'yesterday');
    },

    getExpiredDomains : function (db){
        return getArrayFromDatabase(db, 'expired_list');
    }


};

const getArrayFromDatabase = function(db, collection){
    return new Promise((resolve,reject)=>{
        db.collection(collection).find({}).toArray((err,result)=>{
            if (err){
                reject('Error reading collection');
            }else{
                resolve(result);
            }
        });
    });
}