I trying to make Account Schema with achievements key property as array of ref objectsIDs and another properties, but can't figure out how to do this. When pushing data only ref objectId is pushed without another properties.
Is there better way than just storing in one array object Refs and in another another properties?
achievements: [{achievement: {type: Schema.Types.ObjectId, ref: 'Achievement'}}, {
claimed: {
type: Boolean,
default: false
}
}, {
isDone:
{type: Boolean, default: false}
}, {
current:
{type: Number, default: 0}
}],
AccountSchema.statics.addAllExistingAchievements = (account: any) => {
return new Promise((resolve, reject) => {
return Achievement.find().exec().then((achievements: any) => {
achievements.map((achievement: any, index: number) => {
account.achievements.push({achievement: achievement}, {claimed: false}, {isDone: false}, {current: 0})
if (achievements.length - 1 === index) {
account.save();
}
})
resolve({success: true});
}).catch((e: any) => reject(e));
}
)
}