Files
zod-backend/src/saving-goals/dtos/response/saving-goal-details.response.dto.ts
2024-12-15 12:44:59 +03:00

50 lines
1.3 KiB
TypeScript

import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { DocumentMetaResponseDto } from '~/document/dtos/response';
import { SavingGoal } from '~/saving-goals/entities';
import { CategoryResponseDto } from './category-response.dto';
export class SavingGoalDetailsResponseDto {
@ApiProperty()
id!: string;
@ApiProperty()
name!: string;
@ApiPropertyOptional()
description?: string;
@ApiProperty()
dueDate!: Date;
@ApiProperty()
targetAmount!: number;
@ApiProperty()
currentAmount!: number;
@ApiPropertyOptional({ type: CategoryResponseDto, isArray: true })
categories?: CategoryResponseDto[];
@ApiPropertyOptional({ type: DocumentMetaResponseDto, isArray: true })
image: DocumentMetaResponseDto | null;
@ApiProperty()
createdAt!: Date;
@ApiProperty()
updatedAt!: Date;
constructor(data: SavingGoal) {
this.id = data.id;
this.name = data.name;
this.description = data.description;
this.dueDate = data.dueDate;
this.targetAmount = data.targetAmount;
this.currentAmount = data.currentAmount;
this.categories = data.categories ? data.categories.map((category) => new CategoryResponseDto(category)) : [];
this.image = data.image ? new DocumentMetaResponseDto(data.image) : null;
this.createdAt = data.createdAt;
this.updatedAt = data.updatedAt;
}
}