nestjs swagger default apiproperty to current date

Viewed 1810

This is my code:

  @IsDate()
  @ApiProperty({
    type: Number,
  })
  updateTime: Date;

How can I add default value to current date

2 Answers

From the docs, you can change your code to following:

@ApiProperty({
  type: Number,
  default: new Date().now() // or something else...
})

There is a separate annotation called UpdateDateColumn for storing updated date times.

  @IsOptional({ groups: [CREATE, UPDATE] })
  @UpdateDateColumn({ nullable: true })
  updateTime: Date;

The import statement is as follows -

import { PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Column } from 'typeorm';
Related