mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-06 05:40:02 -06:00
fix: remove prisma types import in runtime (#1228)
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
"name": "storybook",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "storybook dev -p 6006",
|
||||
"build": "tsup",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { TResponseData } from "@formbricks/types/v1/responses";
|
||||
import { TSurveyQuestion } from "@formbricks/types/v1/surveys";
|
||||
import { TSurveyQuestion, TSurveyStatus } from "@formbricks/types/v1/surveys";
|
||||
import { TUserNotificationSettings } from "@formbricks/types/v1/users";
|
||||
import { SurveyStatus } from "@prisma/client";
|
||||
|
||||
export interface Insights {
|
||||
totalCompletedResponses: number;
|
||||
@@ -50,7 +49,7 @@ type SurveyData = {
|
||||
id: string;
|
||||
name: string;
|
||||
questions: TSurveyQuestion[];
|
||||
status: SurveyStatus;
|
||||
status: TSurveyStatus;
|
||||
responses: ResponseData[];
|
||||
displays: DisplayData[];
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { TActionClassType } from "@formbricks/types/v1/actionClasses";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { EventType } from "@prisma/client";
|
||||
|
||||
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
||||
const environmentId = req.query.environmentId?.toString();
|
||||
@@ -24,9 +24,9 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
|
||||
return res.status(400).json({ message: "Missing eventName" });
|
||||
}
|
||||
|
||||
let eventType: EventType = EventType.code;
|
||||
let eventType: TActionClassType = "code";
|
||||
if (eventName === "Exit Intent (Desktop)" || eventName === "50% Scroll") {
|
||||
eventType = EventType.automatic;
|
||||
eventType = "automatic";
|
||||
}
|
||||
|
||||
const eventData = await prisma.event.create({
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import "server-only";
|
||||
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { TAction } from "@formbricks/types/v1/actions";
|
||||
import { TActionClassType } from "@formbricks/types/v1/actionClasses";
|
||||
import { TAction, TActionInput, ZActionInput } from "@formbricks/types/v1/actions";
|
||||
import { ZOptionalNumber } from "@formbricks/types/v1/common";
|
||||
import { ZId } from "@formbricks/types/v1/environment";
|
||||
import { DatabaseError, ResourceNotFoundError } from "@formbricks/types/v1/errors";
|
||||
import { EventType, Prisma } from "@prisma/client";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { revalidateTag, unstable_cache } from "next/cache";
|
||||
import { getActionClassCacheTag } from "../actionClass/service";
|
||||
import { SERVICES_REVALIDATION_INTERVAL, ITEMS_PER_PAGE } from "../constants";
|
||||
import { ITEMS_PER_PAGE, SERVICES_REVALIDATION_INTERVAL } from "../constants";
|
||||
import { getSessionCached } from "../session/service";
|
||||
import { validateInputs } from "../utils/validate";
|
||||
import { TActionInput, ZActionInput } from "@formbricks/types/v1/actions";
|
||||
import { ZOptionalNumber } from "@formbricks/types/v1/common";
|
||||
|
||||
export const getActionsCacheTag = (environmentId: string): string => `environments-${environmentId}-actions`;
|
||||
|
||||
@@ -78,9 +78,9 @@ export const createAction = async (data: TActionInput): Promise<TAction> => {
|
||||
validateInputs([data, ZActionInput]);
|
||||
const { environmentId, name, properties, sessionId } = data;
|
||||
|
||||
let eventType: EventType = EventType.code;
|
||||
let eventType: TActionClassType = "code";
|
||||
if (name === "Exit Intent (Desktop)" || name === "50% Scroll") {
|
||||
eventType = EventType.automatic;
|
||||
eventType = "automatic";
|
||||
}
|
||||
|
||||
const session = await getSessionCached(sessionId);
|
||||
|
||||
@@ -10,12 +10,12 @@ import {
|
||||
TProfileUpdateInput,
|
||||
ZProfileUpdateInput,
|
||||
} from "@formbricks/types/v1/profile";
|
||||
import { MembershipRole, Prisma } from "@prisma/client";
|
||||
import { unstable_cache, revalidateTag } from "next/cache";
|
||||
import { validateInputs } from "../utils/validate";
|
||||
import { deleteTeam } from "../team/service";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { revalidateTag, unstable_cache } from "next/cache";
|
||||
import { z } from "zod";
|
||||
import { SERVICES_REVALIDATION_INTERVAL } from "../constants";
|
||||
import { deleteTeam } from "../team/service";
|
||||
import { validateInputs } from "../utils/validate";
|
||||
|
||||
const responseSelection = {
|
||||
id: true,
|
||||
@@ -112,7 +112,7 @@ const updateUserMembership = async (teamId: string, userId: string, role: TMembe
|
||||
};
|
||||
|
||||
const getAdminMemberships = (memberships: TMembership[]): TMembership[] =>
|
||||
memberships.filter((membership) => membership.role === MembershipRole.admin);
|
||||
memberships.filter((membership) => membership.role === "admin");
|
||||
|
||||
// function to update a user's profile
|
||||
export const updateProfile = async (
|
||||
@@ -196,13 +196,13 @@ export const deleteProfile = async (userId: string): Promise<TProfile> => {
|
||||
const teamAdminMemberships = getAdminMemberships(teamMemberships);
|
||||
const teamHasAtLeastOneAdmin = teamAdminMemberships.length > 0;
|
||||
const teamHasOnlyOneMember = teamMemberships.length === 1;
|
||||
const currentUserIsTeamOwner = role === MembershipRole.owner;
|
||||
const currentUserIsTeamOwner = role === "owner";
|
||||
|
||||
if (teamHasOnlyOneMember) {
|
||||
await deleteTeam(teamId);
|
||||
} else if (currentUserIsTeamOwner && teamHasAtLeastOneAdmin) {
|
||||
const firstAdmin = teamAdminMemberships[0];
|
||||
await updateUserMembership(teamId, firstAdmin.userId, MembershipRole.owner);
|
||||
await updateUserMembership(teamId, firstAdmin.userId, "owner");
|
||||
} else if (currentUserIsTeamOwner) {
|
||||
await deleteTeam(teamId);
|
||||
}
|
||||
|
||||
@@ -27,11 +27,15 @@ export const ZActionClassNoCodeConfig = z.object({
|
||||
|
||||
export type TActionClassNoCodeConfig = z.infer<typeof ZActionClassNoCodeConfig>;
|
||||
|
||||
export const ZActionClassType = z.enum(["code", "noCode", "automatic"]);
|
||||
|
||||
export type TActionClassType = z.infer<typeof ZActionClassType>;
|
||||
|
||||
export const ZActionClass = z.object({
|
||||
id: z.string().cuid2(),
|
||||
name: z.string(),
|
||||
description: z.string().nullable(),
|
||||
type: z.enum(["code", "noCode", "automatic"]),
|
||||
type: ZActionClassType,
|
||||
noCodeConfig: z.union([ZActionClassNoCodeConfig, z.null()]),
|
||||
environmentId: z.string(),
|
||||
createdAt: z.date(),
|
||||
|
||||
@@ -267,10 +267,16 @@ export type TSurveyAttributeFilter = z.infer<typeof ZSurveyAttributeFilter>;
|
||||
|
||||
const ZSurveyDisplayOption = z.enum(["displayOnce", "displayMultiple", "respondMultiple"]);
|
||||
|
||||
export type TSurveyDisplayOption = z.infer<typeof ZSurveyDisplayOption>;
|
||||
|
||||
const ZSurveyType = z.enum(["web", "email", "link", "mobile"]);
|
||||
|
||||
export type TSurveyType = z.infer<typeof ZSurveyType>;
|
||||
|
||||
const ZSurveyStatus = z.enum(["draft", "inProgress", "paused", "completed"]);
|
||||
|
||||
export type TSurveyStatus = z.infer<typeof ZSurveyStatus>;
|
||||
|
||||
export const ZSurvey = z.object({
|
||||
id: z.string().cuid2(),
|
||||
createdAt: z.date(),
|
||||
|
||||
Reference in New Issue
Block a user