Skip to content

Commit

Permalink
feat(frontend): create schemas for data validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielborgesdm committed Jun 4, 2024
1 parent 9139704 commit 3e8b66b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
21 changes: 11 additions & 10 deletions frontend/src/components/Schemas/AuthorSchema.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as yup from "yup"
import * as yup from "yup";

const AuthorSchema = yup
.object({
name: yup.string().required().min(1).max(300),
email: yup.string().email().min(1).max(320),
nationality: yup.string().min(1).max(100),
birthDate: yup.string().matches(/^(?:(?:19|20)\d{2})-(?:(?:0[1-9]|1[0-2]))-(?:(?:0[1-9]|[12]\d|3[01]))$/, { message: "Follow the format AAAA-MM-DD" }),
})
.required()
.object({
name: yup.string().required().min(1).max(300),
email: yup.string().email().min(1).max(320),
nationality: yup.string().min(1).max(100),
birthDate: yup.string().matches(/^(?:(?:19|20)\d{2})-(?:(?:0[1-9]|1[0-2]))-(?:(?:0[1-9]|[12]\d|3[01]))$/, {
message: "Follow the format AAAA-MM-DD",
}),
})
.required();


export default AuthorSchema
export default AuthorSchema;
10 changes: 10 additions & 0 deletions frontend/src/components/Schemas/BookSchema.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as yup from "yup";

const BookSchema = yup
.object({
title: yup.string().min(1).max(300).required(),
pages: yup.number().min(1).required(),
})
.required();

export default BookSchema;

0 comments on commit 3e8b66b

Please sign in to comment.