I have
app.useGlobalPipes(new ValidationPipe()); that works well for my schemas. API returns 400 and error messages.
The problem is when I pass incorrect data in sub schema:
@Schema({ _id: false })
class Question {
@Prop({ required: true })
text: string;
@Prop({ required: true })
correct: boolean;
}
const QuestionSchema = SchemaFactory.createForClass(Question);
export type QuizDocument = Quiz & Document & ITimestamp;
@Schema({ timestamps: true })
export class Quiz {
@Prop({ required: true })
name: string;
@Prop({ required: true })
description: string;
@Prop()
file: string;
// THERE IS THE PROBLEM:
@Prop({ required: true, type: [QuestionSchema] })
questions: MongooseSchema.Types.Array;
}
export const QuizSchema = SchemaFactory.createForClass(Quiz);
In this case - for incorrect text and correct fields from QuestionSchema API returns 500.