downgrade test
This commit is contained in:
parent
9173647b26
commit
e93b059dad
|
@ -6,7 +6,7 @@ import {
|
||||||
getLingdocsUser,
|
getLingdocsUser,
|
||||||
updateLingdocsUser,
|
updateLingdocsUser,
|
||||||
} from "../lib/couch-db";
|
} from "../lib/couch-db";
|
||||||
import { createNewUser, canRemoveOneOutsideProvider } from "../lib/user-utils";
|
import { createNewUser, canRemoveOneOutsideProvider, downgradeUser } from "../lib/user-utils";
|
||||||
import {
|
import {
|
||||||
getHash,
|
getHash,
|
||||||
getURLToken,
|
getURLToken,
|
||||||
|
@ -191,6 +191,18 @@ const authRouter = (passport: PassportStatic) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post("/downgradeToBasic", async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
if (!req.user) {
|
||||||
|
return res.redirect("/");
|
||||||
|
}
|
||||||
|
await downgradeUser(req.user.userId);
|
||||||
|
res.redirect("/");
|
||||||
|
} catch (e) {
|
||||||
|
next(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.delete("/admin/:userId", async (req, res, next) => {
|
router.delete("/admin/:userId", async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
// TODO: MAKE PROPER MIDDLEWARE WITH TYPING
|
// TODO: MAKE PROPER MIDDLEWARE WITH TYPING
|
||||||
|
|
|
@ -53,7 +53,6 @@ paymentRouter.post(
|
||||||
case 'customer.subscription.created':
|
case 'customer.subscription.created':
|
||||||
subscription = event.data.object;
|
subscription = event.data.object;
|
||||||
status = subscription.status;
|
status = subscription.status;
|
||||||
console.log({ subscription });
|
|
||||||
console.log(`Upgrading user ${userId}.`);
|
console.log(`Upgrading user ${userId}.`);
|
||||||
await upgradeUser(userId);
|
await upgradeUser(userId);
|
||||||
// TODO: save subscription to db
|
// TODO: save subscription to db
|
||||||
|
@ -97,7 +96,8 @@ paymentRouter.post("/create-checkout-session", async (req, res, next) => {
|
||||||
subscription_data: {
|
subscription_data: {
|
||||||
metadata: {
|
metadata: {
|
||||||
userId: req.user.userId,
|
userId: req.user.userId,
|
||||||
}
|
startTime: Date.now(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mode: 'subscription',
|
mode: 'subscription',
|
||||||
success_url: `https://account.lingdocs.com/user?upgrade=success`,
|
success_url: `https://account.lingdocs.com/user?upgrade=success`,
|
||||||
|
|
|
@ -67,6 +67,11 @@
|
||||||
</form>
|
</form>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
<% if (user.tester && user.level === "student") { %>
|
||||||
|
<form action="/downgradeToBasic" method="POST">
|
||||||
|
<button class="btn btn-sm btn-secondary" type="submit">Downgrade Account</button>
|
||||||
|
</form>
|
||||||
|
<% } %>
|
||||||
<% if (user.email) { %>
|
<% if (user.email) { %>
|
||||||
<h4 class="mt-3 mb-3">Password <i class="fas fa-key ml-2"></i></h4>
|
<h4 class="mt-3 mb-3">Password <i class="fas fa-key ml-2"></i></h4>
|
||||||
<% if (!user.password) { %>
|
<% if (!user.password) { %>
|
||||||
|
|
Loading…
Reference in New Issue