@@ -28,16 +28,23 @@ export const hasApiKeySchema = Joi.object({
2828 userId : Joi . number ( ) . required ( ) ,
2929} )
3030
31+ const singleTagSchema = Joi . string ( )
32+ . pattern ( / ^ [ A - Z a - z 0 - 9 - _ ] + $ / )
33+ . max ( 25 )
34+
3135const tagSchema = Joi . array ( )
3236 . max ( MAX_NUM_TAGS_PER_LINK )
3337 . optional ( )
38+ // letters, numbers, hyphens, underscores, 25 digits
3439 . items (
35- Joi . string ( ) . custom ( ( tag : string , helpers ) => {
36- if ( ! isValidTag ( tag ) ) {
37- return helpers . message ( { custom : `tag: ${ tag } format is invalid` } )
38- }
39- return tag
40- } ) ,
40+ singleTagSchema
41+ . custom ( ( tag : string , helpers ) => {
42+ if ( ! isValidTag ( tag ) ) {
43+ return helpers . error ( 'tag:invalid' )
44+ }
45+ return tag
46+ } )
47+ . messages ( { 'tag:invalid' : 'Tag format is invalid.' } ) ,
4148 )
4249 . unique ( ( a , b ) => a === b )
4350
@@ -60,13 +67,13 @@ export const userTagsQueryConditions = Joi.object({
6067 . min ( 3 )
6168 . custom ( ( tag : string , helpers ) => {
6269 if ( ! isValidTag ( tag ) ) {
63- return helpers . message ( {
64- custom : `tag: ${ tag } query format is invalid.` ,
65- } )
70+ return helpers . error ( 'tag:invalid' )
6671 }
6772 return tag
6873 } )
74+ . messages ( { 'tag:invalid' : 'Tag format is invalid.' } )
6975 . required ( ) ,
76+
7077 limit : Joi . number ( ) . required ( ) ,
7178} )
7279
0 commit comments