validation.ts56 lines, 2.0 KB
| 1 | import Joi from "joi"; |
| 2 | |
| 3 | export const createNoteSchema = Joi.object({ |
| 4 | title: Joi.string().min(1).max(200).required().messages({ |
| 5 | "string.min": "Title must be at least 1 character long", |
| 6 | "string.max": "Title must not exceed 200 characters", |
| 7 | "any.required": "Title is required", |
| 8 | }), |
| 9 | content: Joi.string().min(1).max(50000).required().messages({ |
| 10 | "string.min": "Content must be at least 1 character long", |
| 11 | "string.max": "Content must not exceed 50,000 characters", |
| 12 | "any.required": "Content is required", |
| 13 | }), |
| 14 | tagIds: Joi.array().items(Joi.string().uuid()).optional().messages({ |
| 15 | "array.base": "Tag IDs must be an array", |
| 16 | "string.uuid": "Each tag ID must be a valid UUID", |
| 17 | }), |
| 18 | }); |
| 19 | |
| 20 | export const updateNoteSchema = Joi.object({ |
| 21 | title: Joi.string().min(1).max(200).optional().messages({ |
| 22 | "string.min": "Title must be at least 1 character long", |
| 23 | "string.max": "Title must not exceed 200 characters", |
| 24 | }), |
| 25 | content: Joi.string().min(1).max(50000).optional().messages({ |
| 26 | "string.min": "Content must be at least 1 character long", |
| 27 | "string.max": "Content must not exceed 50,000 characters", |
| 28 | }), |
| 29 | tagIds: Joi.array().items(Joi.string().uuid()).optional().messages({ |
| 30 | "array.base": "Tag IDs must be an array", |
| 31 | "string.uuid": "Each tag ID must be a valid UUID", |
| 32 | }), |
| 33 | }); |
| 34 | |
| 35 | export const getNotesByUserSchema = Joi.object({ |
| 36 | page: Joi.number().integer().min(1).optional().default(1).messages({ |
| 37 | "number.base": "Page must be a number", |
| 38 | "number.integer": "Page must be an integer", |
| 39 | "number.min": "Page must be at least 1", |
| 40 | }), |
| 41 | limit: Joi.number() |
| 42 | .integer() |
| 43 | .min(1) |
| 44 | .max(100) |
| 45 | .optional() |
| 46 | .default(10) |
| 47 | .messages({ |
| 48 | "number.base": "Limit must be a number", |
| 49 | "number.integer": "Limit must be an integer", |
| 50 | "number.min": "Limit must be at least 1", |
| 51 | "number.max": "Limit must not exceed 100", |
| 52 | }), |
| 53 | search: Joi.string().max(200).optional().messages({ |
| 54 | "string.max": "Search query must not exceed 200 characters", |
| 55 | }), |
| 56 | }); |