mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-27 15:39:50 -05:00
8ea6016cf5
* add first part of sync service * add actionClasses to js sync * fix errors, add product to sync * rewrite formbricks-js for new states and types * fix tests * fix build errors * add cors * fix cors errors and other bugs * comment test in checks until working again
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
"use server";
|
|
|
|
import { prisma } from "@formbricks/database";
|
|
import { DatabaseError } from "@formbricks/errors";
|
|
import { TActionClass } from "@formbricks/types/v1/actionClasses";
|
|
import "server-only";
|
|
|
|
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 createActionClassServerAction = async (environmentId: string, actionClass) => {
|
|
try {
|
|
const result = await prisma.eventClass.create({
|
|
data: {
|
|
...actionClass,
|
|
environment: { connect: { id: environmentId } },
|
|
},
|
|
});
|
|
return result;
|
|
} catch (error) {
|
|
throw new DatabaseError(`Database error when creating an action for environment ${environmentId}`);
|
|
}
|
|
};
|