Skip to content

Commit

Permalink
feat: slugSchema, slug pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Feb 2, 2019
1 parent bd3a045 commit f897db6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/validation/joi/joi.shared.schemas.ts
Expand Up @@ -21,6 +21,19 @@ export const idSchema = stringSchema
.min(6)
.max(64)

/**
* `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
*/
export const SLUG_PATTERN = /^[a-z0-9-]*$/

/**
* "Slug" - a valid URL, filename, etc.
*/
export const slugSchema = stringSchema
.regex(SLUG_PATTERN)
.min(1)
.max(255)

// 16725225600 is 2500-01-01
export const unixTimestampSchema = numberSchema
.integer()
Expand Down
2 changes: 1 addition & 1 deletion src/validation/joi/joi.validation.error.ts
Expand Up @@ -7,7 +7,7 @@ export interface JoiValidationErrorData extends ErrorData {
}

export class JoiValidationError extends AppError {
constructor (message: string, data: JoiValidationErrorData) {
constructor (message: string, public data: JoiValidationErrorData) {
super(message, data)
}
}

0 comments on commit f897db6

Please sign in to comment.