Subscriptions
This commit is contained in:
@@ -4,14 +4,56 @@ 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.newResult = (paymentResult) => {
|
||||
return DB.paymentsCols.insertOne(paymentResult).catch((err)=>{
|
||||
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;
|
||||
});
|
||||
|
||||
@@ -153,6 +153,11 @@ userDB = (DB) => {
|
||||
});
|
||||
}
|
||||
|
||||
DB.isSubscriptor = async (profileid) => {
|
||||
const profile = DB.getProfileCache(profileid);
|
||||
return profile && profile.subscription && profile.subscription > (new Date() - 0);
|
||||
}
|
||||
|
||||
//Groups
|
||||
DB.getGroups = async (excludePrivate = false) => {
|
||||
let query = {
|
||||
|
||||
Reference in New Issue
Block a user