manifold/functions/src/on-update-group.ts
2022-07-14 20:51:38 -05:00

22 lines
726 B
TypeScript

import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
import { Group } from '../../common/group'
const firestore = admin.firestore()
export const onUpdateGroup = functions.firestore
.document('groups/{groupId}')
.onUpdate(async (change) => {
const prevGroup = change.before.data() as Group
const group = change.after.data() as Group
// ignore the update we just made
if (prevGroup.mostRecentActivityTime !== group.mostRecentActivityTime)
return
// TODO: create notification with isSeeOnHref set to the group's /group/questions url
await firestore
.collection('groups')
.doc(group.id)
.update({ mostRecentActivityTime: Date.now() })
})