🚹 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@bubojs/validation

Package Overview
Dependencies
Maintainers
4
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bubojs/validation

[Back to Main Menu](.././../README.md#validateur-de-route)

Source
npmnpm
Version
0.1.0-dev.eae45c98fbb7f8846356daa5cdc37a7826d334fa
Version published
Maintainers
4
Created
Source

Fastest Validator

Back to Main Menu

Ce middleware de validation de route est construit autours de fatestValidator n'hesitez pas Ă  regarder la documentation pour en savoir plus

schema de validation

Vous pouvez utiliser le typage fournit par FastestValidator que permet de créer un schéma typé pour fastest ex :

const userCreateValidations: FastestValidator<User> = {
    schema: {
      $$async: true,
      username: { type: 'string', min: 3, max: 255 },
      email: { type: 'email', normalize: true },
      password: this.passwordValidation,
      birthDate: {
        optional: true,
        type: 'date',
        convert: true
      },
      bio: { type: 'string', optional: true }
    },
    validatorOptions: {
      useNewCustomCheckerFunction: true, // using new version
      messages: {
        // Register our new error message text
        atLeastOneLetter: 'The pass value must contain at least one letter from a-z ranges!',
        atLeastOneUpperCaseLetter: 'The pass value must contain at least one letter from A-Z ranges!',
        atLeastOneDigit: 'The pass value must contain at least one digit from 0 to 9!',
        atLeastOneSpecialCharacter: 'The pass value must contain at least one special character!',
        emailNotAvailable: `The email is already registered!`
      }
    }
  }

Ajout du schéma à la route

une fois le schéma créé il faut l'ajouter sur la route à valider, il y a un decorateur pour cela :

import { Body, Controller, Post } from '@bubojs/api'
import { AuthMiddleware, ValidationMiddleware } from '@bubojs/catalog'

@Controller()
class AuthController {
    @ValidationMiddleware(userCreateValidations)
    @Post('/signup')
    async signup(@Body() body: any) {
        ...
    }
}

ainsi le schéma s'ajoute à la route

Back to Main Menu

FAQs

Package last updated on 31 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts