Hello everyone! I'm facing an issue with mongoose. It seems to be adding an array of arrays to the database instead of just an object array, and it's packaging each object into its own array. Can someone help me figure out what's going wrong?
Here is my PaymentMethod code:
export class PaymentMethod{
@prop({ required: true, unique: true })
public name: String
@prop({ required: true })
public details: String
@prop({ required: true })
public inlineMenu: String
@prop({ required: true })
public callbackData: String
@prop({ required: true })
public fee: Array<IPaymentFee>
@prop({ default: false })
public available: Boolean
}
And here is the IPaymentFee Interface:
export interface IPaymentFee {
from: Number
type: 'percent' | 'fixed'
amount: Number
extra?: Number | 0
}
After setting up the models, I create a new payment method instance like this:
const createdPayment = await PaymentMethodModel.create({
name: 'xbank',
details: '43284809328432',
inlineMenu: 'menu_payment_xbank',
callbackData: 'client_payment_xbank',
available: true,
fee: [
{ from: 0, type: 'fixed', amount: 200 },
{ from: 1000, type: 'percent', amount: 20, extra: 150 },
{ from: 1500, type: 'percent', amount: 17 },
{ from: 2000, type: 'percent', amount: 15 },
{ from: 3500, type: 'percent', amount: 13 },
{ from: 10000, type: 'percent', amount: 12 },
{ from: 20000, type: 'percent', amount: 11 },
{ from: 30000, type: 'percent', amount: 10 },
]}
)
Unfortunately, I'm getting an incorrect result with an array of arrays instead of an array of objects -- screenshot here
Can anyone spot what I might be doing wrong? Thank you in advance for your help!