I am trying to condition the execution of an if statement based on a Boolean value in an object in my DB. For some reason it always executes. I am new to TypeScript so I might be getting something basic wrong.
This is my code:
exports.newCommunity = functions.firestore.document('communities/{communityID}').onCreate((snap, context) => {
const community = snap.data();
if (community !== undefined) {
if (community.public == true) {
return createCommunityInAlgolia(community);
} else {
return null;
};
} else {
return null;
};
});
I tried also having this as the if statement (community.public === true)
or even simply this (community.public)
(as the value is a Boolean). But it always executes.
I can't find any other reason in my code for this function to execute. What am I doing wrong?