Skip to content

Commit

Permalink
make firestore ref private
Browse files Browse the repository at this point in the history
  • Loading branch information
choden-dev committed Mar 10, 2024
1 parent 3b25317 commit cc20b34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/__generated__
**/__generated__
**/*.index.html
6 changes: 4 additions & 2 deletions server/src/data-layer/adapters/FirestoreCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const converter = <T>() => ({
fromFirestore: (doc: any) => doc.data() as T
})

export const firestore = Object.assign(
const firestore = Object.assign(
() => {
return admin.firestore()
},
Expand All @@ -22,6 +22,8 @@ export const firestore = Object.assign(
}
)

export const db = {
const db = {
users: firestore.collection<UserAdditionalInfo>("users")
} as const

export default db
14 changes: 8 additions & 6 deletions server/src/data-layer/services/UserService.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { db } from "data-layer/adapters/FirestoreCollections"
import FirestoreCollections from "data-layer/adapters/FirestoreCollections"
import { UserAdditionalInfo } from "data-layer/models/firebase"

export default class UserService {
// Create
public async addUser(uid: string, additionalInfo: UserAdditionalInfo) {
await db.users.doc(uid).set(additionalInfo)
await FirestoreCollections.users.doc(uid).set(additionalInfo)
}

// Read
public async getUsers() {
const res = await db.users.get()
const res = await FirestoreCollections.users.get()
const users = res.docs.map((user) => {
return user.data()
})
return users
}

public async getUser(uid: string) {
const userDoc = await db.users.doc(uid).get()
const userDoc = await FirestoreCollections.users.doc(uid).get()
return userDoc.data()
}

Expand All @@ -30,11 +30,13 @@ export default class UserService {
uid: string,
updatedFields: Partial<UserAdditionalInfo>
) {
await db.users.doc(uid).set(updatedFields, { merge: true })
await FirestoreCollections.users
.doc(uid)
.set(updatedFields, { merge: true })
}

// Delete
public async deleteUser(uid: string) {
await db.users.doc(uid).delete()
await FirestoreCollections.users.doc(uid).delete()
}
}

0 comments on commit cc20b34

Please sign in to comment.