team creation clean done
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user