Added tag to forms

This commit is contained in:
Ceferino Patino 2022-08-18 16:46:06 -04:00
commit 40e072c99f
3 changed files with 11 additions and 1 deletions

View file

@ -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 {

View file

@ -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(

View file

@ -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);
}