mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-31 03:19:06 -06:00
* feat: server rendering of event actions summary page & server actions * chore: renaming event to action and minor refactoring * fix: logging message * delete: unnecessary file * feat: migrate attributes overview page * feat: impl grouped page & layout, logically differentiate attributes and actions * pnpm format * fix: logical addressing of dirs and minot bugs * move: actionsAndAttributes navbar to dedicated dir from components * fix: use server-only build-time checks and move actionsAttributes navbar * revert: unnecessary docker compose changes * resolve merge conflicts dynamically * fix: address feedback comments * use sparkles icon from heroicons * fix updated action not updating in table * remove async from client function due to warning * move router.refresh in AddNoActionModal * small rename * feat: replace swr w server action in ActionSettingsTab * replace custom error with ResourceNotFoundError error class --------- Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
"use server";
|
|
import 'server-only'
|
|
|
|
import { prisma } from "@formbricks/database";
|
|
import { DatabaseError } from "@formbricks/errors";
|
|
import { TAttributeClass } from "@formbricks/types/v1/attributeClasses";
|
|
|
|
export const transformPrismaAttributeClass = (attributeClass): TAttributeClass | null => {
|
|
if (attributeClass === null) {
|
|
return null;
|
|
}
|
|
|
|
const transformedAttributeClass: TAttributeClass = {
|
|
...attributeClass,
|
|
};
|
|
|
|
return transformedAttributeClass;
|
|
};
|
|
|
|
export const getAttributeClasses = async (environmentId: string): Promise<TAttributeClass[]> => {
|
|
try {
|
|
let attributeClasses = await prisma.attributeClass.findMany({
|
|
where: {
|
|
environmentId: environmentId,
|
|
},
|
|
orderBy: {
|
|
createdAt: "asc",
|
|
},
|
|
});
|
|
const transformedAttributeClasses: TAttributeClass[] = attributeClasses
|
|
.map(transformPrismaAttributeClass)
|
|
.filter((attributeClass): attributeClass is TAttributeClass => attributeClass !== null);
|
|
|
|
return transformedAttributeClasses;
|
|
} catch (error) {
|
|
throw new DatabaseError(`Database error when fetching attributeClasses for environment ${environmentId}`);
|
|
}
|
|
};
|
|
|
|
export const updatetAttributeClass = async (
|
|
attributeClassId: string,
|
|
data: { description?: string; archived?: boolean }
|
|
): Promise<TAttributeClass | null> => {
|
|
try {
|
|
let attributeClass = await prisma.attributeClass.update({
|
|
where: {
|
|
id: attributeClassId,
|
|
},
|
|
data: {
|
|
description: data.description,
|
|
archived: data.archived,
|
|
},
|
|
});
|
|
const transformedAttributeClass: TAttributeClass | null = transformPrismaAttributeClass(attributeClass);
|
|
|
|
return transformedAttributeClass;
|
|
} catch (error) {
|
|
throw new DatabaseError(
|
|
`Database error when updating attribute class with id ${attributeClassId}`
|
|
);
|
|
}
|
|
};
|