-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use zod for validation on create endpoint (#1391)
* add @liveinstantly/dash-mpd-parser and zod dependencies * add createRoomSchema for room creation validation * use zod validations in createRoom rather than manual checks. * actually get rid of duplicate checks * try to use infer * add zod back to package.json * fix lint * add zod-validation-error dependency * use z.infer for OttApiRequestRoomCreate * move zod schema to ott common and fix lint * fix import * add error messages * added zoderror handling to errorhandler * add zod error to error handler * fix error message * updated zod schema to account for regex and reserved room names. * removed duplicate checks. * update unit tests in create endpoint * update zod schema * add zod dependency to ott-common * remove duplicate checks --------- Co-authored-by: Carson McManus <[email protected]>
- Loading branch information
1 parent
4187c67
commit 1137ce7
Showing
7 changed files
with
73 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ROOM_NAME_REGEX } from "ott-common/constants"; | ||
import { Visibility, QueueMode } from "ott-common/models/types"; | ||
import { z } from "zod"; | ||
|
||
// These strings are not allowed to be used as room names. | ||
const RESERVED_ROOM_NAMES = ["list", "create", "generate"]; | ||
|
||
export const createRoomSchema = z.object({ | ||
name: z | ||
.string() | ||
.min(3, "too short, must be atleast 3 characters") | ||
.max(32, "too long, must be at most 32 characters") | ||
.regex(ROOM_NAME_REGEX) | ||
.refine(name => !RESERVED_ROOM_NAMES.includes(name), { message: "not allowed (reserved)" }), | ||
title: z.string().max(255, "too long, must be at most 255 characters").optional(), | ||
description: z.string().optional(), | ||
isTemporary: z.boolean().optional().default(true), | ||
visibility: z.nativeEnum(Visibility).default(Visibility.Public).optional(), | ||
queueMode: z.nativeEnum(QueueMode).optional(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters