team creation clean done

This commit is contained in:
Arjun Patel
2022-01-14 12:17:59 -08:00
parent 46ab74119f
commit 00d256b43b
7 changed files with 103 additions and 14 deletions
+5 -5
View File
@@ -1,18 +1,18 @@
import { User as FirUser } from "firebase/auth";
import { Firestore, getFirestore, doc, getDoc, setDoc, Timestamp, serverTimestamp } from "firebase/firestore";
import { User } from '../models/user'
import { Collections } from "./collections";
export default class UserService {
private db : Firestore = getFirestore()
private static collectionName: string = "users"
// give back the avatar based on the person's google account avatar
getUserAvatar(displayName: string) {
return `https://ui-avatars.com/api/?name=${displayName}`
}
async getUser(userId: string) : Promise<User | null> {
const docRef = doc(this.db, UserService.collectionName, userId);
const docRef = doc(this.db, Collections.users, userId);
const docSnap = await getDoc(docRef);
if (docSnap.exists()) {
@@ -28,12 +28,12 @@ export default class UserService {
}
async createUser(userId: string, emailAddress: string, avatarUrl: string) {
const docRef = doc(this.db, UserService.collectionName, userId);
const docRef = doc(this.db, Collections.users, userId);
await setDoc(docRef, { emailAddress, avatarUrl, createdDate: serverTimestamp() }, { merge: true })
}
async updateUser(user: User) {
const docRef = doc(this.db, UserService.collectionName, user.id);
const docRef = doc(this.db, Collections.users, user.id);
await setDoc(docRef, { ...user, lastUpdatedDate: serverTimestamp() }, { merge: true })
}
}