in my NestJS app I have currently an Product schema and a payment method schema as subdocument in the product schema.
@Schema()
export class Product {
@Prop({ required: true })
name: string;
@Prop([PaymentDetails])
payments: PaymentDetails[];
}
@Schema()
export class PaymentDetails {
@Prop()
method: String;
@Prop({ type: Boolean, default: false })
isDefault: Boolean;
}
Now for validation purpose I created a DTO for the payment method. When I want to add the payment method to my product, then the push()
-methods expects an instance of PaymentDetails[]
. How to use my DTO now to create/push a new entry?
async addPayment(user: IUser, productId: string, payment: PaymentMethodDto) {
const filter = { _id: productId };
let p = await this.productModel.findOne<ProductDocument>(filter).exec();
p.payments.push(`PaymentDetails[] expected`))
return p.save();
}