Decrement follow count on unfollow
This commit is contained in:
parent
7008164d25
commit
f6b357cbc4
|
@ -21,7 +21,6 @@ export const addUserToContractFollowers = async (
|
||||||
id: user.id,
|
id: user.id,
|
||||||
createdTime: Date.now(),
|
createdTime: Date.now(),
|
||||||
})
|
})
|
||||||
// TODO: decrement for unfollows
|
|
||||||
await firestore
|
await firestore
|
||||||
.collection(`contracts`)
|
.collection(`contracts`)
|
||||||
.doc(contract.id)
|
.doc(contract.id)
|
||||||
|
|
|
@ -30,6 +30,7 @@ export * from './score-contracts'
|
||||||
export * from './weekly-markets-emails'
|
export * from './weekly-markets-emails'
|
||||||
export * from './reset-betting-streaks'
|
export * from './reset-betting-streaks'
|
||||||
export * from './reset-weekly-emails-flag'
|
export * from './reset-weekly-emails-flag'
|
||||||
|
export * from './on-delete-contract-follow'
|
||||||
|
|
||||||
// v2
|
// v2
|
||||||
export * from './health'
|
export * from './health'
|
||||||
|
|
24
functions/src/on-delete-contract-follow.ts
Normal file
24
functions/src/on-delete-contract-follow.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import * as functions from 'firebase-functions'
|
||||||
|
import * as admin from 'firebase-admin'
|
||||||
|
import { FieldValue } from 'firebase-admin/firestore'
|
||||||
|
|
||||||
|
export const onDeleteContractFollow = functions.firestore
|
||||||
|
.document('contracts/{contractId}/follows/{userId}')
|
||||||
|
.onDelete(async (change, context) => {
|
||||||
|
const { contractId } = context.params as {
|
||||||
|
contractId: string
|
||||||
|
}
|
||||||
|
const firestore = admin.firestore()
|
||||||
|
const contract = await firestore
|
||||||
|
.collection(`contracts`)
|
||||||
|
.doc(contractId)
|
||||||
|
.get()
|
||||||
|
if (!contract.exists) throw new Error('Could not find contract')
|
||||||
|
|
||||||
|
await firestore
|
||||||
|
.collection(`contracts`)
|
||||||
|
.doc(contractId)
|
||||||
|
.update({
|
||||||
|
followerCount: FieldValue.increment(-1),
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user