I'm currently working on constructing a Schema that includes a nested object. I am trying to define default values and required properties within the nested object, but it seems like the options I set are being ignored.
task.entity.ts
@Schema()
export class Task {
@Prop({ required: true }) // This is functioning correctly
language: Language
@Prop({ type: TaskContent, required: true })
content: TaskContent
}
class TaskContent extends Document {
@Prop({ required: true, default: "Hello World" }) // The settings for this property are not taking effect.
message: string
}
export type TaskDocument = Task & Document
export const TaskSchema = SchemaFactory.createForClass(Task)
Within my task.service.ts:
const task = new this.taskSchema({
...dataFromPostRequest
})
const result = await task.save()
return result
Is there a way I can properly include an object while utilizing the @Prop options from the nested object? I prefer not to consolidate everything into one class, but rather split them up as intended.