add id, userId to comment
This commit is contained in:
parent
2ea05f8913
commit
55dabd2dc9
|
@ -1,10 +1,14 @@
|
|||
// Currently, comments are created after the bet, not atomically with the bet.
|
||||
// They're uniquely identified by the pair contractId/betId.
|
||||
export type Comment = {
|
||||
id: string
|
||||
contractId: string
|
||||
betId: string
|
||||
userId: string
|
||||
|
||||
text: string
|
||||
createdTime: number
|
||||
|
||||
// Denormalized, for rendering comments
|
||||
userName?: string
|
||||
userUsername?: string
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
where,
|
||||
orderBy,
|
||||
} from 'firebase/firestore'
|
||||
|
||||
import { getValues, listenForValues } from './utils'
|
||||
import { db } from './init'
|
||||
import { User } from '../../../common/user'
|
||||
|
@ -21,15 +22,20 @@ export async function createComment(
|
|||
commenter: User
|
||||
) {
|
||||
const ref = doc(getCommentsCollection(contractId), betId)
|
||||
return await setDoc(ref, {
|
||||
|
||||
const comment: Comment = {
|
||||
id: ref.id,
|
||||
contractId,
|
||||
betId,
|
||||
userId: commenter.id,
|
||||
text,
|
||||
createdTime: Date.now(),
|
||||
userName: commenter.name,
|
||||
userUsername: commenter.username,
|
||||
userAvatarUrl: commenter.avatarUrl,
|
||||
})
|
||||
}
|
||||
|
||||
return await setDoc(ref, comment)
|
||||
}
|
||||
|
||||
function getCommentsCollection(contractId: string) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user