mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-05 02:58:36 -06:00
* add new zod schema for responses * add new client endpoints for responses * add services for responses and surveys * add new responses model to webhooks & email --------- Co-authored-by: Johannes <johannes@formbricks.com>
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { TResponse, TResponseInput, TResponseUpdateInput } from "@formbricks/types/v1/responses";
|
|
|
|
export const createResponse = async (responseInput: TResponseInput, apiHost: string): Promise<TResponse> => {
|
|
const res = await fetch(`${apiHost}/api/v1/client/responses`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(responseInput),
|
|
});
|
|
if (!res.ok) {
|
|
console.error(res.text);
|
|
throw new Error("Could not create response");
|
|
}
|
|
const resJson = await res.json();
|
|
return resJson.data;
|
|
};
|
|
|
|
export const updateResponse = async (
|
|
responseInput: TResponseUpdateInput,
|
|
responseId: string,
|
|
apiHost: string
|
|
): Promise<TResponse> => {
|
|
const res = await fetch(`${apiHost}/api/v1/client/responses/${responseId}`, {
|
|
method: "PUT",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(responseInput),
|
|
});
|
|
if (!res.ok) {
|
|
throw new Error("Could not update response");
|
|
}
|
|
const resJson = await res.json();
|
|
return resJson.data;
|
|
};
|