Hey all, I'm new to NestJS and having an issue when trying to validate an array of enums using class validator in my DTO. The enum has a structure like this:
export class Tag {
static readonly ANGULAR = new Tag('Angular', 'red');
static readonly TYPESCRIPT = new Tag('TypeScript', 'darkblue');
static readonly NODEJS = new Tag('NodeJS', 'green');
private constructor(
private readonly key: string,
public readonly color: string,
) {}
toString() {
return this.key;
}
}
and my DTO looks like this:
import { IsString, IsArray } from 'class-validator';
import { Tag } from '../models/tag.enum';
export class CreateProjectDto {
@IsString()
name: string;
@IsString()
summary: string;
@IsString()
description: string;
@IsString()
projectLink: string;
@IsArray()
images: string[];
@IsArray()
tags: Tag[];
}
However when I use this DTO in my service for my create method which looks like this:
create(createProjectDto: CreateProjectDto) {
return this.prisma.project.create({
data: createProjectDto,
});
}
it comes up with an error for the data property which is attached.
Any help would be appreciated, thanks!