mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-12 09:39:39 -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>
106 lines
2.8 KiB
TypeScript
106 lines
2.8 KiB
TypeScript
"use server";
|
|
import "server-only";
|
|
|
|
import { prisma } from "@formbricks/database";
|
|
import { DatabaseError, ResourceNotFoundError } from "@formbricks/errors";
|
|
import { TActionClass, TActionClassInput } from "@formbricks/types/v1/actionClasses";
|
|
|
|
const select = {
|
|
id: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
name: true,
|
|
description: true,
|
|
type: true,
|
|
noCodeConfig: true,
|
|
environmentId: true,
|
|
};
|
|
|
|
export const getActionClasses = async (environmentId: string): Promise<TActionClass[]> => {
|
|
try {
|
|
let actionClasses = await prisma.eventClass.findMany({
|
|
where: {
|
|
environmentId: environmentId,
|
|
},
|
|
select,
|
|
orderBy: {
|
|
createdAt: "asc",
|
|
},
|
|
});
|
|
|
|
return actionClasses;
|
|
} catch (error) {
|
|
throw new DatabaseError(`Database error when fetching actions for environment ${environmentId}`);
|
|
}
|
|
};
|
|
|
|
export const deleteActionClass = async (
|
|
environmentId: string,
|
|
actionClassId: string
|
|
): Promise<TActionClass> => {
|
|
try {
|
|
const result = await prisma.eventClass.delete({
|
|
where: {
|
|
id: actionClassId,
|
|
},
|
|
select,
|
|
});
|
|
if (result === null) throw new ResourceNotFoundError("Action", actionClassId);
|
|
|
|
return result;
|
|
} catch (error) {
|
|
throw new DatabaseError(
|
|
`Database error when deleting an action with id ${actionClassId} for environment ${environmentId}`
|
|
);
|
|
}
|
|
};
|
|
|
|
export const createActionClass = async (
|
|
environmentId: string,
|
|
actionClass: TActionClassInput
|
|
): Promise<TActionClass> => {
|
|
try {
|
|
const result = await prisma.eventClass.create({
|
|
data: {
|
|
name: actionClass.name,
|
|
description: actionClass.description,
|
|
type: actionClass.type,
|
|
noCodeConfig: actionClass.noCodeConfig
|
|
? JSON.parse(JSON.stringify(actionClass.noCodeConfig))
|
|
: undefined,
|
|
environment: { connect: { id: environmentId } },
|
|
},
|
|
select,
|
|
});
|
|
return result;
|
|
} catch (error) {
|
|
throw new DatabaseError(`Database error when creating an action for environment ${environmentId}`);
|
|
}
|
|
};
|
|
|
|
export const updateActionClass = async (
|
|
environmentId: string,
|
|
actionClassId: string,
|
|
inputActionClass: Partial<TActionClassInput>
|
|
): Promise<TActionClass> => {
|
|
try {
|
|
const result = await prisma.eventClass.update({
|
|
where: {
|
|
id: actionClassId,
|
|
},
|
|
data: {
|
|
name: inputActionClass.name,
|
|
description: inputActionClass.description,
|
|
type: inputActionClass.type,
|
|
noCodeConfig: inputActionClass.noCodeConfig
|
|
? JSON.parse(JSON.stringify(inputActionClass.noCodeConfig))
|
|
: undefined,
|
|
},
|
|
select,
|
|
});
|
|
return result;
|
|
} catch (error) {
|
|
throw new DatabaseError(`Database error when updating an action for environment ${environmentId}`);
|
|
}
|
|
};
|