Skip to content

Instantly share code, notes, and snippets.

@alexb4a
Last active July 6, 2023 15:15
Show Gist options
  • Save alexb4a/a1335c3e714c99827528d3d9a93fee7d to your computer and use it in GitHub Desktop.
Save alexb4a/a1335c3e714c99827528d3d9a93fee7d to your computer and use it in GitHub Desktop.
A very INEFFICIENT way to retrieve all Employees.
// This Cloud Code Function returns all objects from Person that have the isEmployee property set to True
Parse.Cloud.define("getEmployees", async (request) => {
const Person = Parse.Object.extend("Person"); // Instantiates the Person Class
const query = new Parse.Query(Person); // Instantiates a new Query for the Person Class
const tempArray = await query.find(); // Retrieves all Person objects
let finalArray = []; // Creates an empty array to store results
// Loops through the results retreived by the Query
for (let i = 0; i < tempArray.length; i++){
// If isEmployee property is true
if (tempArray[i].get("isEmployee")){
// Pushes the object to the final Array
finalArray.push(tempArray[i]);
}
}
// Returns the final array
return finalArray;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment