64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
const DBName = "EMI_SOCIAL";
|
|
|
|
postDB = (DB)=>{
|
|
DB.paymentsCols = DB.db.db(DBName).collection("payments");
|
|
|
|
DB.newIntent = (intent) => {
|
|
intent.ts = new Date();
|
|
return DB.paymentsCols.insertOne(intent).catch((err)=>{
|
|
console.log(err);
|
|
return false;
|
|
});
|
|
}
|
|
|
|
DB.getIntent = (client_secret) => {
|
|
return DB.paymentsCols.findOne({client_secret}).catch((err)=>{
|
|
console.log(err);
|
|
return false;
|
|
});
|
|
}
|
|
|
|
DB.newResult = (paymentResult, client_secret) => {
|
|
if(!client_secret)
|
|
return DB.paymentsCols.insertOne(paymentResult).catch((err)=>{
|
|
console.log(err);
|
|
return false;
|
|
});
|
|
const update = {
|
|
$set: {
|
|
payment: paymentResult.result
|
|
}
|
|
}
|
|
return DB.paymentsCols.updateOne({client_secret}, update, {upsert: 1}).catch((err)=>{
|
|
console.log(err);
|
|
return false;
|
|
});
|
|
}
|
|
|
|
//Maybe this should be in dbTools/profile.js
|
|
DB.updateProfileSubscription = (profileid, restart=false) => {
|
|
const inc = 1000 * 60 * 60 * 24 * 30; //30 days
|
|
let update = {};
|
|
if(restart){
|
|
update = {
|
|
$set: {
|
|
subscription: (new Date() - 0 ) + inc,
|
|
}
|
|
}
|
|
}else{
|
|
update = {
|
|
$inc: {
|
|
subscription: inc,
|
|
}
|
|
}
|
|
}
|
|
const _id = DB.ObjectID(profileid);
|
|
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
|
console.log(err);
|
|
return false;
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = postDB; |