Files
formbricks/packages/lib/services/attributeClass.ts
Shubham Palriwala 3824d95151 Move Actions & Attributes pages over to server components (#495)
* 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>
2023-07-18 12:40:03 +02:00

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}`
);
}
};