downgrade users when trial ends (#767)
* wip * wip * wip * wtf * should be all the logic * comment * fix receiver name * safeguard a bit more * downgrade users cron job Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
0372289fe6
commit
a4fbe7b2b4
6 files changed
+129
-25
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import dayjs from "dayjs";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@lib/prisma";
|
||||
|
||||
const TRIAL_LIMIT_DAYS = 14;
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.query.apiKey;
|
||||
if (process.env.CRON_API_KEY !== apiKey) {
|
||||
return res.status(401).json({ message: "Not authenticated" });
|
||||
}
|
||||
|
||||
await prisma.user.updateMany({
|
||||
data: {
|
||||
plan: "FREE",
|
||||
},
|
||||
where: {
|
||||
plan: "TRIAL",
|
||||
createdDate: {
|
||||
lt: dayjs().subtract(TRIAL_LIMIT_DAYS, "day").toDate(),
|
||||
},
|
||||
},
|
||||
});
|
||||
res.json({ ok: true });
|
||||
}
|
||||
Reference in new issue
Block a user