fix: Prisma validation error in generateMetadata (workflows) (#18149)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import type { PageProps } from "app/_types";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
import { WithLayout } from "app/layoutHOC";
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { cache } from "react";
|
||||
import { z } from "zod";
|
||||
|
||||
// import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";
|
||||
@@ -9,17 +11,25 @@ import LegacyPage from "@calcom/features/ee/workflows/pages/workflow";
|
||||
import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
|
||||
|
||||
const querySchema = z.object({
|
||||
workflow: z.string(),
|
||||
workflow: z
|
||||
.string()
|
||||
.refine((val) => !isNaN(Number(val)), {
|
||||
message: "workflow must be a string that can be cast to a number",
|
||||
})
|
||||
.transform((val) => Number(val)),
|
||||
});
|
||||
|
||||
export const generateMetadata = async ({ params, searchParams }: PageProps) => {
|
||||
const getWorkflow = cache((id: number) => WorkflowRepository.getById({ id }));
|
||||
|
||||
export const generateMetadata = async ({ params, searchParams }: PageProps): Promise<Metadata | null> => {
|
||||
const parsed = querySchema.safeParse({ ...params, ...searchParams });
|
||||
if (!parsed.success) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const workflow = await WorkflowRepository.getById({ id: +parsed.data.workflow });
|
||||
|
||||
const workflow = await getWorkflow(parsed.data.workflow);
|
||||
if (!workflow) {
|
||||
notFound();
|
||||
}
|
||||
return await _generateMetadata(
|
||||
(t) => (workflow && workflow.name ? workflow.name : t("untitled")),
|
||||
() => ""
|
||||
|
||||
@@ -68,7 +68,7 @@ export class WorkflowRepository {
|
||||
private static log = logger.getSubLogger({ prefix: ["workflow"] });
|
||||
|
||||
static async getById({ id }: TGetInputSchema) {
|
||||
return await prisma.workflow.findFirst({
|
||||
return await prisma.workflow.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user