Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

custom validator Whitelisting

/*
* Even if your object is an instance of a validation class 
* it can contain additional properties that are not defined. 
* If you do not want to have such properties on your object, 
* pass special flag to validate method:
*/

import {validate, Allow, Min} from "class-validator";

export class Post {

    @Allow()
    title: string;

    @Min(0)
    views: number;

    nonWhitelistedProperty: number;
}

let post = new Post();
post.title = 'Hello world!';
post.views = 420;

post.nonWhitelistedProperty = 69;
(post as any).anotherNonWhitelistedProperty = "something";

validate(post).then(errors => {
  // post.nonWhitelistedProperty is not defined
  // (post as any).anotherNonWhitelistedProperty is not defined
  ...
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: react app environment variables undefined even when starts with REACT_APP_ 
Javascript :: sails commands 
Javascript :: react get padding 
Javascript :: setImmediate clearImmediate 
Javascript :: Electron manage windows 
Javascript :: id always returing null angular 
Javascript :: serverless web app with react netlify 
Javascript :: Uncaught Error: Too many re-renders 
Javascript :: how to format date dd/mm/yyyy in javascript 
Javascript :: Using toLocaleString() to Print JavaScript Number Format with Commas 
Javascript :: Without a custom hook example in react 
Javascript :: Method definition shorthand in ES6 
Javascript :: used as a function, Number() will convert another value 
Javascript :: how to send Flutter Color as json || convert String to Color Flutter 
Javascript :: find a node that match a spesific selector string in the paren 
Javascript :: all files website checker 
Javascript :: //testing 
Javascript :: javascript while function is not defined wait 
Javascript :: jsx tag with children react js 
Javascript :: get seo friendly url values in javascript 
Javascript :: discord.js play song 
Javascript :: how to add jquery.zoom in angular 
Javascript :: provider not found react 
Javascript :: display toggle jquery for few seconds 
Javascript :: js collection 
Javascript :: string in vue.js 
Javascript :: javascript random function 
Javascript :: Remove all index from array except the one jquery 
Javascript :: convert jquery hide function to pure javascript code 
Javascript :: time ago function web 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =