Based on the Event entity import { ApiProperty } from '@nestjs/swagger';


import { AbstractDto } from '../../../common/dto/abstract.dto';
import { LocationEntity } from '../../location/entities/location.entity';
import { EventEntity } from '../entities/event.entity';


export class EventDto extends AbstractDto {
    @ApiProperty({
        description: 'Name of location',
        type: String,
    })
    name: string;


    @ApiProperty({
        description: 'Color of location',
        type: Number,
    })
    color: number;


    @ApiProperty({
        description: 'Date of event',
        type: Date,
    })
    date: Date;


    @ApiProperty({
        description: 'Location of event',
        type: () => LocationEntity,
        nullable: true,
    })
    location: LocationEntity;


    constructor(event: EventEntity) {
        super(event);


        this.name = event.name;
        this.color = event.color;
        this.date = event.date;
        this.location = event.location;
    }
}
 and dto import { ApiProperty } from '@nestjs/swagger';
import {
    IsDate,
    IsNotEmpty,
    IsNumber,
    IsOptional,
    IsString,
    Max,
    Min,
} from 'class-validator';


export class EventCreateDto {
    @ApiProperty({
        description: 'name of event',
        type: String,
    })
    @IsString({ message: 'should be string' })
    @IsNotEmpty()
    name: string;


    @ApiProperty({
        description: 'color of event',
        type: Number,
        default: 1,
    })
    @IsNumber()
    @Min(1)
    @Max(20)
    color: number;


    @ApiProperty({
        description: 'date of event',
        type: Date,
        nullable: true,
    })
    @IsDate()
    @IsOptional()
    date?: Date;


    @ApiProperty({
        description: 'id of location',
        type: Number,
    })
    @IsOptional()
    @IsNumber()
    locationId: number;
}
that is implemented in the services below   async create(createEventDto: EventCreateDto): Promise<EventDto> {
        const event = new EventEntity();
        event.name = createEventDto.name;
        event.color = createEventDto.color;
        event.date = createEventDto.date;


        if (createEventDto.locationId) {
            const location = await this.locationRepository.findOne({
                where: {
                    id: createEventDto.locationId,
                },
            });
            event.location = location;
        }
        const createdEvent = await this.eventRepository.save(event);
        return new EventDto(createdEvent);
    }


    async update(id: number, dto: EventUpdateDto): Promise<EventDto> {
        const event = await this.eventRepository.findOne({
            where: { id },
        });


        if (!event) {
            throw new NotFoundException();
        }


        const { name, color, date, locationId } = dto;


        if (name !== undefined) {
            event.name = name;
        }


        if (color !== undefined) {
            event.color = color;
        }


        if (date !== undefined) {
            event.date = date;
        }


        if (locationId !== undefined) {
            const location = await this.locationRepository.findOne({
                where: {
                    id: locationId,
                },
            });


            if (!location) {
                throw new NotFoundException();
            }


            event.location = location;
        }


        const updatedEvent = await this.eventRepository.save(event);


        return new EventDto(updatedEvent);
    } why do i get an internal 500 error and this error [Nest] 6764  - 06/06/2023, 11:23:26 PM   ERROR [ExceptionsHandler] Class constructor LocationDto cannot be invoked without 'new'
TypeError: Class constructor LocationDto cannot be invoked without 'new'
 
