Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#125 [FIX]: Yup restrictions on protocol title, column text, option t… #126

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/controllers/applicationAnswerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export const createApplicationAnswer = async (req: Request, res: Response) => {
id: yup.number(),
date: yup.date().required(),
applicationId: yup.number().required(),
addressId: yup.number().required(),
addressId: yup.number(),
itemAnswerGroups: yup.array().of(createItemAnswerGroupSchema).min(1).required(),
})
.noUnknown();
Expand Down
8 changes: 3 additions & 5 deletions src/controllers/classroomController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const createClassroom = async (req: Request, res: Response) => {
const createClassroomSchema = yup
.object()
.shape({
name: yup.string().min(3).max(255).required(),
name: yup.string().min(3).max(20).required(),
institutionId: yup.number(),
users: yup.array().of(yup.number()).min(2).required(),
})
Expand Down Expand Up @@ -123,7 +123,7 @@ export const updateClassroom = async (req: Request, res: Response): Promise<void
const updateClassroomSchema = yup
.object()
.shape({
name: yup.string().min(3).max(255),
name: yup.string().min(3).max(20),
institutionId: yup.number(),
users: yup.array().of(yup.number()).min(2),
})
Expand Down Expand Up @@ -210,9 +210,7 @@ export const searchClassroomByName = async (req: Request, res: Response): Promis
// Yup schemas
const searchUserSchema = yup
.object()
.shape({
term: yup.string().min(3).max(20).required(),
})
.shape({ term: yup.string().min(3).max(20).required() })
.noUnknown();
// Yup parsing/validation
const { term } = await searchUserSchema.validate(req.body);
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/protocolController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ export const createProtocol = async (req: Request, res: Response) => {

const tableColumnSchema = yup
.object()
.shape({ text: yup.string().min(3).max(255).required(), placement: yup.number().min(1).required() })
.shape({ text: yup.string().min(1).max(255).required(), placement: yup.number().min(1).required() })
.noUnknown();

const itemOptionsSchema = yup
.object()
.shape({
text: yup.string().min(3).max(255).required(),
text: yup.string().min(1).max(255).required(),
placement: yup.number().min(1).required(),
files: yup.array().of(fileSchema).default([]),
})
Expand Down Expand Up @@ -414,7 +414,7 @@ export const createProtocol = async (req: Request, res: Response) => {
.object()
.shape({
id: yup.number().min(1),
title: yup.string().min(3).max(3000).required(),
title: yup.string().min(3).max(255).required(),
description: yup.string().max(3000),
enabled: yup.boolean().required(),
pages: yup.array().of(pagesSchema).min(1).required(),
Expand Down Expand Up @@ -612,14 +612,14 @@ export const updateProtocol = async (req: Request, res: Response): Promise<void>

const updateTableColumnSchema = yup
.object()
.shape({ id: yup.number().min(1), text: yup.string().min(3).max(255), placement: yup.number().min(1).required() })
.shape({ id: yup.number().min(1), text: yup.string().min(1).max(255), placement: yup.number().min(1).required() })
.noUnknown();

const updateItemOptionsSchema = yup
.object()
.shape({
id: yup.number().min(1),
text: yup.string().min(3).max(255),
text: yup.string().min(1).max(255),
placement: yup.number().min(1).required(),
files: yup.array().of(updateFileSchema).default([]),
})
Expand Down Expand Up @@ -690,7 +690,7 @@ export const updateProtocol = async (req: Request, res: Response): Promise<void>
.object()
.shape({
id: yup.number().min(1),
title: yup.string().min(3).max(3000),
title: yup.string().min(3).max(255),
description: yup.string().max(3000),
enabled: yup.boolean(),
pages: yup.array().of(updatePagesSchema).min(1).required(),
Expand Down
4 changes: 1 addition & 3 deletions src/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ export const searchUserByUsername = async (req: Request, res: Response): Promise
// Yup schemas
const searchUserSchema = yup
.object()
.shape({
term: yup.string().min(3).max(20).required(),
})
.shape({ term: yup.string().min(3).max(20).required() })
.noUnknown();
// Yup parsing/validation
const { term } = await searchUserSchema.validate(req.body);
Expand Down