Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft/timestamp validation class #446

Merged
merged 10 commits into from
Dec 11, 2024
9 changes: 7 additions & 2 deletions apps/drec-api/src/models/AggregateMetervalue.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Unit } from '@energyweb/energy-api-influxdb';
import { IsDate, IsOptional, IsPositive } from 'class-validator';
import { IsNotEmpty, IsOptional, IsPositive } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { IsTimestamp } from '../validations/timestamp';
import { ConvertToNullIfEmpty } from '../transformers/string';
export class NewReadDTO {
@ApiProperty({ type: Date })
@ConvertToNullIfEmpty()
@IsOptional()
@IsTimestamp()
starttimestamp: Date;

@ApiProperty({ type: Date })
@IsDate()
@IsNotEmpty()
@IsTimestamp()
endtimestamp: Date;

@ApiProperty({ type: Number })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import { ReadType } from '../../../utils/enums';
import { Iintermediate, NewReadDTO } from '../../../models';
import { PrimaryGeneratedColumn, Column } from 'typeorm';
import { IsValidTimezone } from '../../../validations/timezone';
import { Transform } from 'class-transformer';
import { Transform, Type } from 'class-transformer';
import { transformTimezone } from '../../../transformers/timezone';
import { Trim } from '../../../transformers/string';

export class IntmediateMeterReadDTO implements Omit<Iintermediate, 'id'> {
@ApiProperty({ type: Number })
@PrimaryGeneratedColumn()
Expand Down Expand Up @@ -46,6 +48,7 @@ export class NewIntmediateMeterReadDTO
@ApiProperty()
@IsString()
@IsOptional()
@Trim()
@IsValidTimezone()
@Transform(transformTimezone)
timezone?: string;
Expand All @@ -61,6 +64,7 @@ export class NewIntmediateMeterReadDTO
@ApiProperty({ type: () => [NewReadDTO] })
@IsArray()
@ValidateNested()
@Type(() => NewReadDTO)
reads: NewReadDTO[];

@ApiProperty({ type: () => Number })
Expand Down
Loading
Loading