feat: attributes data types (#7246)

Co-authored-by: Johannes <johannes@formbricks.com>
This commit is contained in:
Anshuman Pandey
2026-02-13 12:55:06 +04:00
committed by GitHub
parent 36f091bc73
commit f7e8bc1630
176 changed files with 7827 additions and 4073 deletions
@@ -3,6 +3,7 @@ import { cache as reactCache } from "react";
import { prisma } from "@formbricks/database";
import { PrismaErrorType } from "@formbricks/database/types/error";
import { Result, err, ok } from "@formbricks/types/error-handlers";
import { formatSnakeCaseToTitleCase } from "@/lib/utils/safe-identifier";
import { getContactAttributeKeysQuery } from "@/modules/api/v2/management/contact-attribute-keys/lib/utils";
import {
TContactAttributeKeyInput,
@@ -37,7 +38,7 @@ export const getContactAttributeKeys = reactCache(
export const createContactAttributeKey = async (
contactAttributeKey: TContactAttributeKeyInput
): Promise<Result<ContactAttributeKey, ApiErrorResponseV2>> => {
const { environmentId, name, description, key } = contactAttributeKey;
const { environmentId, name, description, key, dataType } = contactAttributeKey;
try {
const prismaData: Prisma.ContactAttributeKeyCreateInput = {
@@ -46,9 +47,10 @@ export const createContactAttributeKey = async (
id: environmentId,
},
},
name,
name: name ?? formatSnakeCaseToTitleCase(key),
description,
key,
...(dataType && { dataType }),
};
const createdContactAttributeKey = await prisma.contactAttributeKey.create({
@@ -30,6 +30,9 @@ export const ZContactAttributeKeyInput = ZContactAttributeKey.pick({
description: true,
environmentId: true,
})
.extend({
dataType: ZContactAttributeKey.shape.dataType.optional(),
})
.superRefine((data, ctx) => {
// Enforce safe identifier format for key
if (!isSafeIdentifier(data.key)) {