I need use an array of Parse.User
objectId's from Parse Platform to fetch this users and save a Parse Object called 'Project' with a column 'Gestor' that have the users who are managers of the project saved.
That is my array:
data.gestor = [
"riid9e82uA",
"tYxICE1ZOf",
"MXYSc0iiYK"
]
There is my function:
let gestors = [];
await data.gestor.forEach(async (value) => {
console.log(value);
let userQuery = new Parse.Query(Parse.User);
userQuery.equalTo('objectId', value);
let newGestor = await userQuery.first();
console.log(JSON.stringify(newGestor, null, 2));
await gestors.push(newGestor);
})
console.log(JSON.stringify(gestors, null, 2));
On the console output I have the Id's, after the code first print the array gestors empty, so I have the objects that I print on console.log() into forEach:
riid9e82uA
aw6cjLgajN
tYxICE1ZOf
[]
{
"username": "teste123@email.com",
"firstName": "ola",
"lastName": "adeus",
"emailVerified": false,
.
.
.
"tYxICE1ZOf": {
"read": true,
"write": true
}
},
"objectId": "tYxICE1ZOf"
}
Why the code executes first the third console.log()
before the second into the forEach and how I can push the objects into an array and after use this array correctly populated to create my new Object?