I am struggling with getting simple firebase queries working to retrieve.
I want to retrieve one documents from the Teams collection where the teamCode="testcode". Then get the an array from that value "Managers" which is a list of document refs. iterate through each manager value creating a new UserTasks document for each manager in the list
TypeError: Cannot read properties of undefined (reading 'Map') at /workspace/team_join_notification.js:21:26
Any help would be appreciated as I'm struggling to understand this :-(
What have you tried so far?
const functions = require('firebase-functions');
const admin = require('firebase-admin');
// To avoid deployment errors, do not call admin.initializeApp() in your code
exports.teamJoinNotification = functions.region('europe-west2').
runWith({
memory: '128MB'
}).https.onCall(
(data, context) => {
const teamRef = data.teamRef;
const userRef = data.userRef;
// Write your code below!
try {
const firestore = admin.firestore();
const querySnaphost = firestore.collection('Teams').where("TeamCode","==" ,"YJ-2024042510").get();
const TeamManagers = [];
//Should only be 1 Team value
//Assign doc ref list to TeamManagers
querySnaphost.docs.Map(function(doc){
TeamManagers = doc.Managers;
});
console.log("Team Managers: " + TeamManagers);
//For each manager in list Get UsedID and add a UserTask.
for(manger in TeamManagers){
const UserId = "";
var now = DateTime.now();
//Get user associtaed to teamManager ref
var querySnaphostUser = firestore.collection('users').where("TeamManagerDocRef","==" , manger).get();
querySnaphostUser.docs.Map(function(doc){
UserId = doc.id;
});
var newUserTask = {'user_ref': UserId, 'task_title': "New Team Member", "task_desc": "Team member has joined", "IsActive": true, "CreationDate": now};
var collection = firestore.collection('UserTasks');
collection
.add(newUserTask) // <-- Your data
.then((_) => console.log('Added User Task'))
.catchError((error) => console.log('Add failed: $error'));
}
console.log('finished');
return 'Hello Team';
}
catch (error){
console.log(error);
}
// Write your code above!
return 'Error';
}
);
Did you check FlutterFlow's Documentation for this topic?