Skip to content
Permalink
Browse files

feat: slugSchema, slug pattern

  • Loading branch information...
kirillgroshkov committed Feb 2, 2019
1 parent bd3a045 commit f897db634fecfa6ac78bf83bb90d3ed1fb2a5dbf
Showing with 14 additions and 1 deletion.
  1. +13 −0 src/validation/joi/joi.shared.schemas.ts
  2. +1 −1 src/validation/joi/joi.validation.error.ts
@@ -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()
@@ -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.
You can’t perform that action at this time.