downgrade test
This commit is contained in:
parent
9173647b26
commit
e93b059dad
|
@ -6,7 +6,7 @@ import {
|
|||
getLingdocsUser,
|
||||
updateLingdocsUser,
|
||||
} from "../lib/couch-db";
|
||||
import { createNewUser, canRemoveOneOutsideProvider } from "../lib/user-utils";
|
||||
import { createNewUser, canRemoveOneOutsideProvider, downgradeUser } from "../lib/user-utils";
|
||||
import {
|
||||
getHash,
|
||||
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) => {
|
||||
try {
|
||||
// TODO: MAKE PROPER MIDDLEWARE WITH TYPING
|
||||
|
|
|
@ -53,7 +53,6 @@ paymentRouter.post(
|
|||
case 'customer.subscription.created':
|
||||
subscription = event.data.object;
|
||||
status = subscription.status;
|
||||
console.log({ subscription });
|
||||
console.log(`Upgrading user ${userId}.`);
|
||||
await upgradeUser(userId);
|
||||
// TODO: save subscription to db
|
||||
|
@ -97,7 +96,8 @@ paymentRouter.post("/create-checkout-session", async (req, res, next) => {
|
|||
subscription_data: {
|
||||
metadata: {
|
||||
userId: req.user.userId,
|
||||
}
|
||||
startTime: Date.now(),
|
||||
},
|
||||
},
|
||||
mode: 'subscription',
|
||||
success_url: `https://account.lingdocs.com/user?upgrade=success`,
|
||||
|
|
|
@ -67,6 +67,11 @@
|
|||
</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) { %>
|
||||
<h4 class="mt-3 mb-3">Password <i class="fas fa-key ml-2"></i></h4>
|
||||
<% if (!user.password) { %>
|
||||
|
|
Loading…
Reference in New Issue