Files
formbricks/packages/lib/instance/service.ts
Dhruwang Jariwala ab80bc1bf2 feat: language switch (#2692)
Co-authored-by: Johannes <johannes@formbricks.com>
Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
2024-06-12 14:10:22 +00:00

45 lines
1.4 KiB
TypeScript

import "server-only";
import { Prisma } from "@prisma/client";
import { prisma } from "@formbricks/database";
import { DatabaseError } from "@formbricks/types/errors";
import { cache } from "../cache";
import { organizationCache } from "../organization/cache";
import { userCache } from "../user/cache";
// Function to check if there are any users in the database
export const getIsFreshInstance = (): Promise<boolean> =>
cache(
async () => {
try {
const userCount = await prisma.user.count();
if (userCount === 0) return true;
else return false;
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseError(error.message);
}
throw error;
}
},
["getIsFreshInstance"],
{ tags: [userCache.tag.byCount()] }
)();
// Function to check if there are any organizations in the database
export const gethasNoOrganizations = (): Promise<boolean> =>
cache(
async () => {
try {
const organizationCount = await prisma.organization.count();
return organizationCount === 0;
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseError(error.message);
}
throw error;
}
},
["gethasNoOrganizations"],
{ tags: [organizationCache.tag.byCount()] }
)();