new code fix

This commit is contained in:
GotPPay
2017-12-14 02:45:51 +01:00
parent a0e2e0a057
commit b4a54e84e7
6 changed files with 63131 additions and 79 deletions

View File

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