validation.ts41 lines, 1.6 KB
| 1 | import Joi from "joi"; |
| 2 | |
| 3 | export const updateProfileSchema = Joi.object({ |
| 4 | firstName: Joi.string().min(1).max(50).optional().messages({ |
| 5 | "string.min": "First name must be at least 1 character long", |
| 6 | "string.max": "First name must not exceed 50 characters", |
| 7 | }), |
| 8 | lastName: Joi.string().min(1).max(50).optional().messages({ |
| 9 | "string.min": "Last name must be at least 1 character long", |
| 10 | "string.max": "Last name must not exceed 50 characters", |
| 11 | }), |
| 12 | bio: Joi.string().max(500).optional().allow("").messages({ |
| 13 | "string.max": "Bio must not exceed 500 characters", |
| 14 | }), |
| 15 | avatarUrl: Joi.string().uri().optional().allow("").messages({ |
| 16 | "string.uri": "Avatar URL must be a valid URL", |
| 17 | }), |
| 18 | preferences: Joi.object().optional().messages({ |
| 19 | "object.base": "Preferences must be a valid object", |
| 20 | }), |
| 21 | }); |
| 22 | |
| 23 | export const createProfileSchema = Joi.object({ |
| 24 | firstName: Joi.string().min(1).max(50).optional().messages({ |
| 25 | "string.min": "First name must be at least 1 character long", |
| 26 | "string.max": "First name must not exceed 50 characters", |
| 27 | }), |
| 28 | lastName: Joi.string().min(1).max(50).optional().messages({ |
| 29 | "string.min": "Last name must be at least 1 character long", |
| 30 | "string.max": "Last name must not exceed 50 characters", |
| 31 | }), |
| 32 | bio: Joi.string().max(500).optional().allow("").messages({ |
| 33 | "string.max": "Bio must not exceed 500 characters", |
| 34 | }), |
| 35 | avatarUrl: Joi.string().uri().optional().allow("").messages({ |
| 36 | "string.uri": "Avatar URL must be a valid URL", |
| 37 | }), |
| 38 | preferences: Joi.object().optional().default({}).messages({ |
| 39 | "object.base": "Preferences must be a valid object", |
| 40 | }), |
| 41 | }); |