timy-messenger/firebase/functions/user-util.js
Franz Heinfling 64d39ac266 Initial commit.
Co-authored-by: Miguel Beltran <m@beltran.work>
2019-10-01 17:26:36 +02:00

30 lines
755 B
JavaScript

const { db } = require('./admin');
const getUsersInGroup = async (groupId) => {
try {
return await db.collection("users")
.where("joinedGroups", "array-contains", groupId)
.get()
} catch (error) {
console.log(`Error getting users for group: ${groupId}`);
}
}
const getUser = (uid) => {
try {
return db
.collection('users')
.doc(uid)
.get();
} catch (error) {
console.error("Error getting user: ", error);
}
}
const usersInChannel = async (groupId, channelId) => {
return await db
.collection(`/groups/${groupId}/channels/${channelId}/users`)
.get();
}
module.exports = { getUser, usersInChannel, getUsersInGroup };