Subscriptions
This commit is contained in:
@@ -57,7 +57,8 @@ DB.getDB.then((DB) => {
|
||||
paymentIntent,
|
||||
userid,
|
||||
price,
|
||||
description
|
||||
description,
|
||||
client_secret: paymentIntent.client_secret,
|
||||
};
|
||||
DB.newIntent(intent);
|
||||
|
||||
@@ -81,7 +82,16 @@ DB.getDB.then((DB) => {
|
||||
result,
|
||||
userid
|
||||
};
|
||||
DB.newResult(payment);
|
||||
//console.log(payment);
|
||||
const intent = await DB.getIntent(result.client_secret);
|
||||
if(intent.description === "Subscription 1 Month"){
|
||||
//update profile subscription status
|
||||
const profileid = getProfileId(req);
|
||||
const isSubscriptor = await DB.isSubscriptor(profileid);
|
||||
const updateR = await DB.updateProfileSubscription(profileid, !isSubscriptor);
|
||||
console.log(updateR);
|
||||
}
|
||||
await DB.newResult(payment, result.client_secret);
|
||||
|
||||
return res.send({
|
||||
status: 'ok'
|
||||
|
||||
@@ -5,9 +5,9 @@ const DB = require("./../mongoDB.js");
|
||||
const Post = require("./../def/post.js");
|
||||
const Notifications = require("./../notifications.js");
|
||||
|
||||
DB.getDB.then((DB)=>{
|
||||
DB.getDB.then((DB) => {
|
||||
|
||||
const getProfileId = (req)=>{
|
||||
const getProfileId = (req) => {
|
||||
return DB.ObjectID(req.cookies.profile_id || req.query.profile_id || req.body.profile_id);
|
||||
}
|
||||
|
||||
@@ -15,13 +15,22 @@ DB.getDB.then((DB)=>{
|
||||
const profileid = getProfileId(req);
|
||||
let posts = await DB.getFeed(profileid);
|
||||
//Add non-organic posts
|
||||
|
||||
|
||||
return res.json(posts)
|
||||
});
|
||||
|
||||
router.get("/usr/:id", async (req, res) => {
|
||||
const profileId = req.params.id;
|
||||
const posts = await DB.getPosts(profileId, getProfileId(req));
|
||||
const viewerProdileId = getProfileId(req);
|
||||
const profile = await DB.getProfileCache(profileId);
|
||||
const posts = await DB.getPosts(profileId, viewerProdileId);
|
||||
if (profile.isCourse) {
|
||||
//check for subscription
|
||||
//const viewerProdile = await DB.getProfileCache(viewerProdileId);
|
||||
//if (!viewerProdile.subscription || viewerProdile.subscription < (new Date()-1)) {
|
||||
// return res.json([posts[posts.length - 1]]);
|
||||
//}
|
||||
}
|
||||
return res.json(posts);
|
||||
});
|
||||
|
||||
@@ -30,10 +39,10 @@ DB.getDB.then((DB)=>{
|
||||
profileid: getProfileId(req),
|
||||
...req.body
|
||||
}
|
||||
if(post.toProfile && await DB.isGroupPrivate(post.toProfile)){
|
||||
if (post.toProfile && await DB.isGroupPrivate(post.toProfile)) {
|
||||
let requestProfile = getProfileId(req) + "";
|
||||
let group = await DB.getProfileCache(post.toProfile);
|
||||
if(!group.subscribed[requestProfile] && group._id != requestProfile){
|
||||
if (!group.subscribed[requestProfile] && group._id != requestProfile) {
|
||||
return res.json({
|
||||
status: "You are not part of this private group",
|
||||
});
|
||||
@@ -44,7 +53,7 @@ DB.getDB.then((DB)=>{
|
||||
let dbr = await DB.newPost(postObj);
|
||||
post = postObj.toObj();
|
||||
post._id = dbr.insertedId;
|
||||
if(post.toProfile && post.toProfile != post.profileid){
|
||||
if (post.toProfile && post.toProfile != post.profileid) {
|
||||
Notifications.youGotANewPost(post)
|
||||
}
|
||||
return res.json({
|
||||
@@ -131,7 +140,7 @@ DB.getDB.then((DB)=>{
|
||||
const post = await DB.getPost(postId);
|
||||
return res.json({
|
||||
status: "ok",
|
||||
... post
|
||||
...post
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user