Currently, I am working on developing a Parse Server API for a cooking-centered social network. One of the key features I am focusing on is creating a function that retrieves recipes. I want this function to be able to display calculated fields such as the title field based on different languages (titleFr, titleEn, titleEs, etc.). I have come across suggestions to use Parse.Promise but I am having trouble implementing it successfully. Despite my efforts, the function only exposes stored fields. Can anyone provide guidance on how to achieve this?
Parse.Cloud.define('getRecipes', function(request, response) {
var lang = getLocale(request); // a custom-made function
var recipes = new Parse.Query("Recipe");
recipes.find().then(function (recipes) {
console.log("Successfully retrieved " + recipes.length + " recipes.");
var recipe = recipes.map(function (recipe) {
recipe.title = recipe.get("title" + lang);
return recipe;
});
return Parse.Promise.when(recipe);
}).then(function (results) {
response.success(results);
}).fail(function(error) {
alert("Error: " + error.code + " " + error.message);
});
});