title: Create custom validation decorator : how it works?
body: <p>I want to create a custom decorator but I think i don't really understand how it works !
  At first I began to validate all not null fields.</p>
  <p>E.G :</p>
  <pre class="lang-js prettyprint-override"><code>    @AllowNull(false)
      @Validate({
          notNull: {
              msg: 'zip code is required',
          },
      })
      @Column({
          type: DataType.STRING,
      })
      zip_code: string;
  
  </code></pre>
  <p>But then I thought &quot;DRY principle is not really applicable there, how can you make a custom validator ?&quot;</p>
  <p>I tried a few things <a href="https://github.com/typestack/class-validator/tree/master#custom-validation-decorators" rel="nofollow noreferrer">class-validator</a> is one of them. But I didn't manage to make it work as intended.</p>
  <p>When sending a request with a <code>null</code> zip_code, custom validation Decorator is not triggered than this field is set to null into the DB for this record (on create or update)</p>
  <p>The best thing I manage to do at this time is</p>
  <pre><code>//required.ts
  export function required(field) {
      return {
          notNull: {
              msg: `${field} is required.`,
          },
      };
  }
  </code></pre>
  <p>I just return the object which <code>@Validate</code> needs to output the correct message</p>
  <pre><code>    @Validate(required('zip_code'))
      @Column({
          type: DataType.STRING,
      })
      zip_code: string;
  
  </code></pre>
  <p>I began using Nest a few days ago. I'm not really familiar with it.
  I'm pretty sure there's an easy way. That's why I'm asking the question here</p>
  <p>Thanks</p>