f50b4775a1
* Allow to follow/unfollow markets, backfill as well * remove yarn script edit * add decrement comment * Lint * Decrement follow count on unfollow * Follow/unfollow button logic * Unfollow/follow => heart * Add user to followers in place-bet and sell-shares * Add tracking * Show contract follow modal for first time following * Increment follower count as well * Remove add follow from bet trigger * restore on-create-bet * Add pubsub to dev.sh, show heart on FR, remove from answer trigger
37 lines
834 B
TypeScript
37 lines
834 B
TypeScript
import * as admin from 'firebase-admin'
|
|
|
|
const firestore = admin.firestore()
|
|
|
|
export const addUserToContractFollowers = async (
|
|
contractId: string,
|
|
userId: string
|
|
) => {
|
|
const followerDoc = await firestore
|
|
.collection(`contracts/${contractId}/follows`)
|
|
.doc(userId)
|
|
.get()
|
|
if (followerDoc.exists) return
|
|
await firestore
|
|
.collection(`contracts/${contractId}/follows`)
|
|
.doc(userId)
|
|
.set({
|
|
id: userId,
|
|
createdTime: Date.now(),
|
|
})
|
|
}
|
|
|
|
export const removeUserFromContractFollowers = async (
|
|
contractId: string,
|
|
userId: string
|
|
) => {
|
|
const followerDoc = await firestore
|
|
.collection(`contracts/${contractId}/follows`)
|
|
.doc(userId)
|
|
.get()
|
|
if (!followerDoc.exists) return
|
|
await firestore
|
|
.collection(`contracts/${contractId}/follows`)
|
|
.doc(userId)
|
|
.delete()
|
|
}
|