new code fix
This commit is contained in:
@@ -17,22 +17,32 @@ module.exports = {
|
||||
return getArrayFromDatabase(db, 'expired_list');
|
||||
},
|
||||
|
||||
cleanExpired : function (db, domain){
|
||||
return new Promise((resolve,reject)=>{
|
||||
db.collection('today').findOne({domainName:domain.domainName}, (err,result)=>{
|
||||
if (err){
|
||||
reject(err);
|
||||
}else{
|
||||
if ((result===null) &&(datetime.create().format('Y-m-d')===domain.expirationDate)){
|
||||
db.collection('expired_list').insert(domain);
|
||||
insertExpired : function (db, domains){
|
||||
return new Promise((resolve, reject)=>{
|
||||
let domainsForInsertion = [];
|
||||
let waitingPromises = [];
|
||||
|
||||
domains.map(domain=>{
|
||||
|
||||
waitingPromises.push(checkDate(db,domain).then(res=>{
|
||||
if (res!==null){
|
||||
domainsForInsertion.push(res);
|
||||
}
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
Promise.all(waitingPromises).then(()=>{
|
||||
if (domainsForInsertion.length>0){
|
||||
db.collection('expired_list').insert(domainsForInsertion, (err,res)=>{
|
||||
resolve();
|
||||
});
|
||||
}else{
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
const getArrayFromDatabase = function(db, collection){
|
||||
@@ -45,4 +55,17 @@ const getArrayFromDatabase = function(db, collection){
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const checkDate = function(db, domain){
|
||||
return new Promise((resolve,reject)=>{
|
||||
db.collection('today').findOne({domainName: domain.domainName}, (err,result)=>{
|
||||
if ((!err) && (result===null) &&(datetime.create().format('Y-m-d')===domain.expirationDate)){
|
||||
//domainsForInsertion.push(domain);
|
||||
resolve(domain);
|
||||
}else{
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user