A
A
Alena Khrenovskaya2018-09-27 16:22:46
JavaScript
Alena Khrenovskaya, 2018-09-27 16:22:46

What can prevent the class-transformer from converting the date?

This is how the form field looks like:
5bacd8c3b20ee161029790.png
This is how the field looks like in the model:

import {Transform, Type} from 'class-transformer';

  @Type(() => Date)
  @Transform(value => value ? moment(value).format('YYYY-MM-DD') : value, { toPlainOnly: true })
  @Transform(value => value ? moment(value) : value, { toClassOnly: true })
  date_of_create: any;

when transforming data from a form into a model using classToPlain (before a post request to the database), I get the following error:
5bacd9981eb76217388810.png
who faced this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question