-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa601a2
commit 9cb8c18
Showing
7 changed files
with
155 additions
and
134 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum HttpOperation { | ||
GET, | ||
POST, | ||
PUT, | ||
DELETE, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,59 @@ | ||
import { z } from "zod"; | ||
import { HttpOperation } from "@/types/enums/httpOperation"; | ||
|
||
// Step schema with custom error messages | ||
export const baseStepSchema = z.object({ | ||
id: z | ||
.string() | ||
.optional() | ||
.transform((val) => (val ? Number(val) : undefined)), | ||
puzzle: z | ||
.string({ required_error: "Required field" }) | ||
.max(1000, { message: "Please enter less than 1000 characters" }), | ||
answer: z | ||
.string({ required_error: "Required field" }) | ||
.max(255, { message: "Please enter less than 255 characters" }), | ||
hint: z | ||
.string({ required_error: "Required field" }) | ||
.max(1000, { message: "Please enter less than 1000 characters" }), | ||
picturePuzzle: z | ||
.string({ required_error: "Required field" }) | ||
.url({ message: "Please provide a valid URL" }), | ||
pictureHint: z | ||
.string({ required_error: "Required field" }) | ||
.url({ message: "Please provide a valid URL" }), | ||
latitude: z.number({ required_error: "Required field" }), | ||
longitude: z.number({ required_error: "Required field" }), | ||
address: z | ||
.string() | ||
.max(255, { message: "Please enter less than 255 characters" }) | ||
.optional(), | ||
city: z | ||
.string() | ||
.max(50, { message: "Please enter less than 50 characters" }) | ||
.optional(), | ||
postalCode: z | ||
.string() | ||
.regex(/^\d{5}$/, { message: "Postal code must be exactly 5 digits" }) | ||
.optional(), | ||
country: z | ||
.string() | ||
.max(50, { message: "Please enter less than 50 characters" }) | ||
.optional(), | ||
stepNumber: z.number({ required_error: "Required field" }).int(), | ||
journeyId: z.number({ required_error: "Required field" }).int(), | ||
}); | ||
export const createStepSchema = (httpOperation: HttpOperation) => { | ||
const baseStepSchema = z.object({ | ||
id: z | ||
.string() | ||
.optional() | ||
.transform((val) => (val ? Number(val) : undefined)), | ||
puzzle: z | ||
.string({ required_error: "Required field" }) | ||
.max(1000, { message: "Please enter less than 1000 characters" }), | ||
answer: z | ||
.string({ required_error: "Required field" }) | ||
.max(255, { message: "Please enter less than 255 characters" }), | ||
hint: z | ||
.string({ required_error: "Required field" }) | ||
.max(1000, { message: "Please enter less than 1000 characters" }), | ||
picturePuzzle: z | ||
.string({ required_error: "Required field" }) | ||
.url({ message: "Please provide a valid URL" }), | ||
pictureHint: z | ||
.string({ required_error: "Required field" }) | ||
.url({ message: "Please provide a valid URL" }), | ||
latitude: z.number({ required_error: "Required field" }), | ||
longitude: z.number({ required_error: "Required field" }), | ||
address: z | ||
.string() | ||
.max(255, { message: "Please enter less than 255 characters" }) | ||
.optional(), | ||
city: z | ||
.string() | ||
.max(50, { message: "Please enter less than 50 characters" }) | ||
.optional(), | ||
postalCode: z | ||
.string() | ||
.regex(/^\d{5}$/, { message: "Postal code must be exactly 5 digits" }) | ||
.optional(), | ||
country: z | ||
.string() | ||
.max(50, { message: "Please enter less than 50 characters" }) | ||
.optional(), | ||
stepNumber: z.number({ required_error: "Required field" }).int(), | ||
journeyId: | ||
httpOperation === HttpOperation.POST | ||
? z.number({ required_error: "Required field" }).int() | ||
: z.number().int().optional(), | ||
}); | ||
|
||
return z.object({ | ||
step: baseStepSchema, | ||
}); | ||
}; | ||
|
||
// Combined schema for the body | ||
export const stepBodySchema = z.object({ | ||
step: baseStepSchema, | ||
}); | ||
// export const stepBodySchema = z.object({ | ||
// step: baseStepSchema, | ||
// }); |