在Dto中填充字段

时间:2020-10-25 15:08:39

标签: postgresql api nestjs

我想知道如何用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,但不知道这是否是我要搜索的内容...

0 个答案:

没有答案