我想知道如何用dto填充dto字段。
我有一个create-recipe.dto.ts
,如下所示:
export class CreateRecetteDto {
@IsNotEmpty()
name: string;
@IsNotEmpty()
difficulty: string;
@IsNotEmpty()
ingredients: string[]
// There are the Id's of the given ingredients
// It would be like : ['aa1azerb','aa1012erb', ...]
}
我有一个ingredient.entity.ts
,如下所示:
@Entity()
export class Ingredient extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@ManyToMany(
type => Recipe,
recipe => recipe.ingredients,
{eager: true},
)
recipes: Recipe[];
}
create-recipe.dto.ts
中的成分并将其转换为成分[]类型而不是字符串[]类型。我看了class-transformator
,但不知道这是否是我要搜索的内容...