diff --git a/client/src/services/fields.js b/client/src/services/fields.js index 5a8295e..4545a94 100644 --- a/client/src/services/fields.js +++ b/client/src/services/fields.js @@ -22,6 +22,7 @@ const askQuestionFields = [ label: 'Text', multiline: true, }, + { id: 'tags', label: 'Tags' }, ]; const commentFields = [ @@ -127,6 +128,7 @@ const searchFields = [ id: 'creator', label: 'Creator', }, + { id: 'tags', label: 'Tags (separated by spaces)' }, ]; export { diff --git a/client/src/services/schemas.js b/client/src/services/schemas.js index f232e96..6261c84 100644 --- a/client/src/services/schemas.js +++ b/client/src/services/schemas.js @@ -21,6 +21,10 @@ const searchSchema = Yup.object({ text: Yup.string().max(300, 'Text must be at most 300 characters, try and use keywords only '), // createdAt: Yup.string().max(11, 'Date must be at most 11 characters, make sure body is formatted correctly'), creator: Yup.string().max(16, 'username must be at most 16 characters'), + tags: Yup.string().matches( + /^(?:\b\w+\b[\s\r\n]*){0,5}$/, + 'Tags should be separated by spaces and are limited to 5' + ), }); const loginSchema = Yup.object({ @@ -71,6 +75,10 @@ const questionSchema = Yup.object({ text: Yup.string() .max(3000, 'Body cannot be longer than 3000 characters') .required('A body is required'), + tags: Yup.string().matches( + /^(?:\b\w+\b[\s\r\n]*){0,5}$/, + 'Tags should be separated by spaces and are limited to 5' + ), }); const patchSchema = Yup.object().shape( diff --git a/server/routes/question/CreateQuestion.js b/server/routes/question/CreateQuestion.js index 0aff3e2..af9ab0f 100644 --- a/server/routes/question/CreateQuestion.js +++ b/server/routes/question/CreateQuestion.js @@ -9,7 +9,7 @@ async function CreateQuestion(req, res) { if (!title || !text) return res.status(400).send(config.errorIncomplete); - if (tags && tags.length > 5) { + if (tags && tags.split(' ').length > 5) { return res.status(400).send(config.errorIncomplete); }