Feat: event-types and tests
This commit is contained in:
1 parent
2e2f6a5e57
commit
a2817a2fee
16 files changed
+15892
-205
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schema = z
|
||||
const schemaEventType = z
|
||||
.object({
|
||||
title: z.string().min(3),
|
||||
slug: z.string().min(3),
|
||||
@@ -8,5 +9,10 @@ const schema = z
|
||||
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 default schema;
|
||||
export { schemaEventType, withValidEventType };
|
||||
+10
-2
@@ -1,8 +1,9 @@
|
||||
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 schema = z
|
||||
const schemaQueryId = z
|
||||
.object({
|
||||
// since nextjs parses query params as strings,
|
||||
// we need to cast them to numbers using z.transform() and parseInt()
|
||||
@@ -12,4 +13,11 @@ const schema = z
|
||||
.transform((id) => parseInt(id)),
|
||||
})
|
||||
.strict();
|
||||
export default schema;
|
||||
|
||||
const withValidQueryId = withValidation({
|
||||
schema: schemaQueryId,
|
||||
type: "Zod",
|
||||
mode: "query",
|
||||
});
|
||||
|
||||
export { schemaQueryId, withValidQueryId };
|
||||
Reference in new issue
Block a user