Here is some code I find myself writing frequently for parsing JSON or creating functions.
// Reusable adder functions
async function addImagesToEntity(entityId, fileName, entity) {
const entity = await db.${entity}.findById(entityId);
await entity.${entity}Images.push({'fileName':fileName});
entity.updated = Date.now();
await entity.save();
//console.log(entity);
}
// I often repeat this pattern for many of my services, and I'm looking to extend it to cover most frontend and backend functionalities. If I can figure out how to do this, I can have a single "CRUD" service for the majority of my use cases.
I encounter this issue frequently when dealing with complex JSON objects and creating dynamic selectors...
I use ${} because that's how I construct strings dynamically, but I am unable to apply it to functions or naming conventions. I want to be able to use a string variable as a function name or method, which is not currently possible. Thank you to anyone who can assist me with this challenge.
Thank you in advance!