The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix #374
Steven Tey76c7d9507e02
diff --git a/app/api/cron/usage/utils.ts b/app/api/cron/usage/utils.tsindex d17ae43c60..694e13319b 100644--- a/app/api/cron/usage/utils.ts+++ b/app/api/cron/usage/utils.ts@@ -1,7 +1,7 @@import { sendEmail } from "emails";import UsageExceeded from "emails/usage-exceeded";import prisma from "#/lib/prisma";-import { log } from "#/lib/utils";+import { getAdjustedBillingCycleStart, log } from "#/lib/utils";import { ProjectProps } from "#/lib/types";import { getTopLinks } from "#/lib/tinybird";import ClicksSummary from "emails/clicks-summary";@@ -42,11 +42,11 @@ export const updateUsage = async () => {// Reset billing cycles for projects that:// - Are not on the free plan// - Are on the free plan but have not exceeded usage- // - Have billingCycleStart today+ // - Have adjustedBillingCycleStart that matches today's dateconst billingReset = projects.filter(({ usage, usageLimit, plan, billingCycleStart }) =>!(plan === "free" && usage > usageLimit) &&- billingCycleStart === new Date().getDate(),+ getAdjustedBillingCycleStart(billingCycleStart) === new Date().getDate(),);// Get all projects that have exceeded usagediff --git a/lib/utils.ts b/lib/utils.tsindex f58b8388f2..0de345a021 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -217,6 +217,23 @@ export const getFirstAndLastDay = (day: number) => {}};+// Function to get the last day of the current month+export const getLastDayOfMonth = () => {+ const today = new Date();+ const lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 0); // This will give the last day of the current month+ return lastDay.getDate();+};++// Adjust the billingCycleStart based on the number of days in the current month+export const getAdjustedBillingCycleStart = (billingCycleStart) => {+ const lastDay = getLastDayOfMonth();+ if (billingCycleStart > lastDay) {+ return lastDay;+ } else {+ return billingCycleStart;+ }+};+export const generateDomainFromName = (name: string) => {const normalizedName = slugify(name, { separator: "" });if (normalizedName.length < 3) {