mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 17:55:17 -04:00
fix: ensure dates are properly transformed
To correctly transform Date objects from ISO-strings in JSON to instances, class-transformer requires the `@Type` annotation. References: https://github.com/typestack/class-transformer#%D1%81onverting-date-strings-into-date-objects Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
59a235ebc4
commit
7e8716ec95
8 changed files with 23 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
import { IsDate, IsOptional, IsString } from 'class-validator';
|
import { IsDate, IsOptional, IsString } from 'class-validator';
|
||||||
|
|
||||||
import { BaseDto } from '../utils/base.dto.';
|
import { BaseDto } from '../utils/base.dto.';
|
||||||
|
@ -10,13 +11,20 @@ import { BaseDto } from '../utils/base.dto.';
|
||||||
export class AuthTokenDto extends BaseDto {
|
export class AuthTokenDto extends BaseDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
label: string;
|
label: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
keyId: string;
|
keyId: string;
|
||||||
|
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
validUntil: Date;
|
validUntil: Date;
|
||||||
|
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
lastUsedAt: Date | null;
|
lastUsedAt: Date | null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
import { IsBoolean, IsDate, IsString } from 'class-validator';
|
import { IsBoolean, IsDate, IsString } from 'class-validator';
|
||||||
|
|
||||||
import { BaseDto } from '../utils/base.dto.';
|
import { BaseDto } from '../utils/base.dto.';
|
||||||
|
@ -24,5 +25,6 @@ export class HistoryEntryImportDto extends BaseDto {
|
||||||
* @example "2020-12-01 12:23:34"
|
* @example "2020-12-01 12:23:34"
|
||||||
*/
|
*/
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
lastVisited: Date;
|
lastVisited: Date;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
import { IsArray, IsBoolean, IsDate, IsString } from 'class-validator';
|
import { IsArray, IsBoolean, IsDate, IsString } from 'class-validator';
|
||||||
|
|
||||||
import { BaseDto } from '../utils/base.dto.';
|
import { BaseDto } from '../utils/base.dto.';
|
||||||
|
@ -30,6 +31,7 @@ export class HistoryEntryDto extends BaseDto {
|
||||||
* @example "2020-12-01 12:23:34"
|
* @example "2020-12-01 12:23:34"
|
||||||
*/
|
*/
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
lastVisitedAt: Date;
|
lastVisitedAt: Date;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
import { IsDate, IsOptional, IsString } from 'class-validator';
|
import { IsDate, IsOptional, IsString } from 'class-validator';
|
||||||
|
|
||||||
import { BaseDto } from '../utils/base.dto.';
|
import { BaseDto } from '../utils/base.dto.';
|
||||||
|
@ -31,6 +32,7 @@ export class MediaUploadDto extends BaseDto {
|
||||||
* @example "2020-12-01 12:23:34"
|
* @example "2020-12-01 12:23:34"
|
||||||
*/
|
*/
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ import {
|
||||||
ValidateNested,
|
ValidateNested,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
|
|
||||||
import { UserInfoDto } from '../users/user-info.dto';
|
|
||||||
import { BaseDto } from '../utils/base.dto.';
|
import { BaseDto } from '../utils/base.dto.';
|
||||||
import { NotePermissionsDto } from './note-permissions.dto';
|
import { NotePermissionsDto } from './note-permissions.dto';
|
||||||
|
|
||||||
|
@ -73,6 +72,7 @@ export class NoteMetadataDto extends BaseDto {
|
||||||
* @example "2020-12-01 12:23:34"
|
* @example "2020-12-01 12:23:34"
|
||||||
*/
|
*/
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ export class NoteMetadataDto extends BaseDto {
|
||||||
* @example "2020-12-01 12:23:34"
|
* @example "2020-12-01 12:23:34"
|
||||||
*/
|
*/
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
import { IsDate, IsNumber, IsOptional, IsString, Min } from 'class-validator';
|
import { IsDate, IsNumber, IsOptional, IsString, Min } from 'class-validator';
|
||||||
|
|
||||||
import { UserInfoDto } from '../users/user-info.dto';
|
import { UserInfoDto } from '../users/user-info.dto';
|
||||||
|
@ -44,6 +45,7 @@ export class EditDto extends BaseDto {
|
||||||
* @example "2020-12-01 12:23:34"
|
* @example "2020-12-01 12:23:34"
|
||||||
*/
|
*/
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@ -52,6 +54,7 @@ export class EditDto extends BaseDto {
|
||||||
* @example "2020-12-01 12:23:34"
|
* @example "2020-12-01 12:23:34"
|
||||||
*/
|
*/
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
import { IsDate, IsNumber } from 'class-validator';
|
import { IsDate, IsNumber } from 'class-validator';
|
||||||
|
|
||||||
import { Revision } from './revision.entity';
|
import { Revision } from './revision.entity';
|
||||||
|
@ -22,6 +23,7 @@ export class RevisionMetadataDto {
|
||||||
* @example "2020-12-01 12:23:34"
|
* @example "2020-12-01 12:23:34"
|
||||||
*/
|
*/
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
import { IsDate, IsNumber, IsString } from 'class-validator';
|
import { IsDate, IsNumber, IsString } from 'class-validator';
|
||||||
|
|
||||||
import { BaseDto } from '../utils/base.dto.';
|
import { BaseDto } from '../utils/base.dto.';
|
||||||
|
@ -38,6 +39,7 @@ export class RevisionDto extends BaseDto {
|
||||||
* @example "2020-12-01 12:23:34"
|
* @example "2020-12-01 12:23:34"
|
||||||
*/
|
*/
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue