Files
formbricks/packages/lib/client/display.ts
Subhodip Roy 60c96fe3f9 Build Display service and rebuild display endpoint in app directory (#432)
* created new create-display and updated display endpoints with zod, db service-layer, and next.js route handlers

* changed the api URL and changed few type definations

* new getTeamDetails service is created which will be further used by display and response endpoints

* changed the prisma call with getTeamDetails service

* created display services and zod validation schema

* removed envId from func parameter

* fix build error by adding a type annotation

* Moved the return inside try block

* Removed comments

* changed the update display service name to markDisplayResponded

* Update route.ts

* reference person type in display, check response code first then transform to json

* add createdAt & updatedAt to person when query display

* pnpm format

* small optimizations

---------

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2023-07-07 12:28:47 +02:00

30 lines
897 B
TypeScript

import { TDisplay, TDisplayInput } from "@formbricks/types/v1/displays";
export const createDisplay = async (
displayCreateRequest: TDisplayInput,
apiHost: string
): Promise<TDisplay> => {
const res = await fetch(`${apiHost}/api/v1/client/displays`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(displayCreateRequest),
});
if (!res.ok) {
console.error(res.text);
throw new Error("Could not create display");
}
const resJson = await res.json();
return resJson.data;
};
export const markDisplayResponded = async (displayId: string, apiHost: string): Promise<void> => {
const res = await fetch(`${apiHost}/api/v1/client/displays/${displayId}/responded`, {
method: "POST",
headers: { "Content-Type": "application/json" },
});
if (!res.ok) {
throw new Error("Could not update display");
}
return;
};