Files
calendar/packages/app-store/ee/routing-forms/lib/getSerializableForm.ts
T
Hariom BalharaGitHubkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
ce41397517 Routing Forms Improvements - Rename routing_forms to routing-forms (#4546)
* Animate fields list and routes list

* Rename routing_forms slug to routing-forms

* Add comments

* Fixtypo

* Add dropdown separator for consistency

* Fix missing occurences of routing_forms and improve types for webhooks

* Fix weird error about title child is an array

* Fix webhook issues

* Fix webhook tests and issues found during fixing them

* Fix lint errors and warnings

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-09-22 22:53:43 +05:30

27 lines
898 B
TypeScript

import { App_RoutingForms_Form } from "@prisma/client";
import { SerializableForm } from "../types/types";
import { zodFields, zodRoutes } from "../zod";
export function getSerializableForm<TForm extends App_RoutingForms_Form>(form: TForm) {
const routesParsed = zodRoutes.safeParse(form.routes);
if (!routesParsed.success) {
throw new Error("Error parsing routes");
}
const fieldsParsed = zodFields.safeParse(form.fields);
if (!fieldsParsed.success) {
throw new Error("Error parsing fields");
}
// Ideally we shouldb't have needed to explicitly type it but due to some reason it's not working reliably with VSCode TypeCheck
const serializableForm: SerializableForm<TForm> = {
...form,
fields: fieldsParsed.data,
routes: routesParsed.data,
createdAt: form.createdAt.toString(),
updatedAt: form.updatedAt.toString(),
};
return serializableForm;
}