mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 02:10:12 -06:00
chore: reintroduce getMonthlyActiveOrganizationPeopleCount
This commit is contained in:
@@ -3,7 +3,7 @@ import { IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants";
|
||||
import { getEnvironment } from "@formbricks/lib/environment/service";
|
||||
import { reverseTranslateSurvey } from "@formbricks/lib/i18n/reverseTranslation";
|
||||
import {
|
||||
// getMonthlyActiveOrganizationPeopleCount,
|
||||
getMonthlyActiveOrganizationPeopleCount,
|
||||
getMonthlyOrganizationResponseCount,
|
||||
getOrganizationByEnvironmentId,
|
||||
} from "@formbricks/lib/organization/service";
|
||||
@@ -47,8 +47,7 @@ export const getUpdatedState = async (environmentId: string, personId?: string):
|
||||
|
||||
// check if Monthly Active Users limit is reached
|
||||
if (IS_FORMBRICKS_CLOUD) {
|
||||
// const currentMau = await getMonthlyActiveOrganizationPeopleCount(organization.id);
|
||||
const currentMau = 0;
|
||||
const currentMau = await getMonthlyActiveOrganizationPeopleCount(organization.id);
|
||||
const monthlyMiuLimit = organization.billing.limits.monthly.miu;
|
||||
|
||||
const isMauLimitReached = monthlyMiuLimit !== null && currentMau >= monthlyMiuLimit;
|
||||
|
||||
@@ -10,6 +10,7 @@ import { getAttributes } from "@formbricks/lib/attribute/service";
|
||||
import { IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants";
|
||||
import { getEnvironment, updateEnvironment } from "@formbricks/lib/environment/service";
|
||||
import {
|
||||
getMonthlyActiveOrganizationPeopleCount,
|
||||
getMonthlyOrganizationResponseCount,
|
||||
getOrganizationByEnvironmentId,
|
||||
} from "@formbricks/lib/organization/service";
|
||||
@@ -85,8 +86,7 @@ export const GET = async (
|
||||
let isMonthlyResponsesLimitReached = false;
|
||||
|
||||
if (IS_FORMBRICKS_CLOUD) {
|
||||
// const currentMau = await getMonthlyActiveOrganizationPeopleCount(organization.id);
|
||||
const currentMau = 0;
|
||||
const currentMau = await getMonthlyActiveOrganizationPeopleCount(organization.id);
|
||||
const monthlyResponseLimit = organization.billing.limits.monthly.responses;
|
||||
const monthlyMiuLimit = organization.billing.limits.monthly.miu;
|
||||
|
||||
|
||||
@@ -276,19 +276,21 @@ export const getMonthlyActiveOrganizationPeopleCount = (organizationId: string):
|
||||
async () => {
|
||||
validateInputs([organizationId, ZId]);
|
||||
|
||||
// temporary workaround due to database performance issues
|
||||
return 0;
|
||||
|
||||
/* try {
|
||||
try {
|
||||
// Define the start of the month
|
||||
// const now = new Date();
|
||||
// const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
|
||||
const organization = await getOrganization(organizationId);
|
||||
|
||||
if (!organization) {
|
||||
throw new ResourceNotFoundError("Organization", organizationId);
|
||||
}
|
||||
|
||||
if (!organization.billing.periodStart) {
|
||||
throw new Error("Organization billing period start is not set");
|
||||
}
|
||||
|
||||
// Get all environment IDs for the organization
|
||||
const products = await getProducts(organizationId);
|
||||
const environmentIds = products.flatMap((product) => product.environments.map((env) => env.id));
|
||||
@@ -299,7 +301,7 @@ export const getMonthlyActiveOrganizationPeopleCount = (organizationId: string):
|
||||
id: true,
|
||||
},
|
||||
where: {
|
||||
AND: [
|
||||
OR: [
|
||||
{ environmentId: { in: environmentIds } },
|
||||
{
|
||||
actions: {
|
||||
@@ -308,15 +310,13 @@ export const getMonthlyActiveOrganizationPeopleCount = (organizationId: string):
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// TODO: @pandeymangg - figure out how to count people based on responses effectively
|
||||
// {
|
||||
// responses: {
|
||||
// some: {
|
||||
// createdAt: { gte: organization.billing.periodStart },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
{
|
||||
responses: {
|
||||
some: {
|
||||
createdAt: { gte: organization.billing.periodStart },
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -328,7 +328,7 @@ export const getMonthlyActiveOrganizationPeopleCount = (organizationId: string):
|
||||
}
|
||||
|
||||
throw error;
|
||||
} */
|
||||
}
|
||||
},
|
||||
[`getMonthlyActiveOrganizationPeopleCount-${organizationId}`],
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user