Feat: event-types and tests

This commit is contained in:
Agusti Fernandez Pardo committed 2022-03-25 06:54:57 +01:00
1 parent 2e2f6a5e57
commit a2817a2fee
16 files changed
+15892 -205

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaEventType = z
.object({
title: z.string().min(3),
slug: z.string().min(3),
length: z.number().min(1).max(1440), // max is a full day.
description: z.string().min(3).optional(),
})
.strict(); // Adding strict so that we can disallow passing in extra fields
const withValidEventType = withValidation({
schema: schemaEventType,
type: "Zod",
mode: "body",
});
export { schemaEventType, withValidEventType };
@@ -0,0 +1,23 @@
import { withValidation } from "next-validations";
import { z } from "zod";
// Extracted out as utility function so can be reused
// at different endpoints that require this validation.
const schemaQueryId = z
.object({
// since nextjs parses query params as strings,
// we need to cast them to numbers using z.transform() and parseInt()
id: z
.string()
.regex(/^\d+$/)
.transform((id) => parseInt(id)),
})
.strict();
const withValidQueryId = withValidation({
schema: schemaQueryId,
type: "Zod",
mode: "query",
});
export { schemaQueryId, withValidQueryId };