adding more loops for the admin page

This commit is contained in:
Arjun Patel
2022-01-14 20:22:22 -08:00
parent d2018bb71a
commit 72faf33dd6
6 changed files with 341 additions and 110 deletions
+37 -6
View File
@@ -158,14 +158,10 @@ export default class TeamService implements IService {
return teamMembers;
}
async getTeamMembersByTeamIdNotUser(
teamId: string,
userId: string
): Promise<TeamMember[]> {
async getTeamMembersByTeamId(teamId: string): Promise<TeamMember[]> {
const q = query(
collection(this.db, Collections.teamMembers),
where("teamId", "==", teamId),
where("userId", "!=", userId)
where("teamId", "==", teamId)
);
const querySnapshot = await getDocs(q);
@@ -192,4 +188,39 @@ export default class TeamService implements IService {
{ merge: true }
);
}
async createTeamInvite(teamMember: TeamMember) {
// if a person was already invited, then update that record, otherwise create a new one
const existingTeamMember = await this.getTeamMemberByEmailInvite(
teamMember.teamId,
teamMember.inviteEmailAddress
);
if (!existingTeamMember) {
const teamMemberRef = await addDoc(
collection(this.db, Collections.teamMembers),
{
...teamMember,
createdDate: serverTimestamp(),
}
);
return;
}
// just update the current user to active since we are activating again
await this.updateTeamMemberStatus(
existingTeamMember.id,
TeamMemberStatus.invited
);
}
async updateTeamMemberStatus(teamMemberId: string, status: TeamMemberStatus) {
const docRef = doc(this.db, Collections.teamMembers, teamMemberId);
await setDoc(
docRef,
{ status, lastUpdatedDate: serverTimestamp() },
{ merge: true }
);
}
}
+4 -5
View File
@@ -38,13 +38,12 @@ export default class UserService {
}
}
async getUserRealtime(
userId: string,
handleDataFetch: (doc: DocumentSnapshot) => void
): Promise<Unsubscribe> {
async getUserRealtime(userId: string): Promise<Unsubscribe> {
const docRef = doc(this.db, Collections.users, userId);
const unsub = onSnapshot(docRef, handleDataFetch);
const unsub = onSnapshot(docRef, (doc) => {
console.log(doc.data());
});
return unsub;
}