edae709f5f
* Add function to parse at mentions * Notify mentioned users on market create - refactor createNotification to accept list of recipients' ids
29 lines
814 B
TypeScript
29 lines
814 B
TypeScript
import * as functions from 'firebase-functions'
|
|
import { getUser } from './utils'
|
|
import { createNotification } from './create-notification'
|
|
import { Group } from '../../common/group'
|
|
|
|
export const onCreateGroup = functions.firestore
|
|
.document('groups/{groupId}')
|
|
.onCreate(async (change, context) => {
|
|
const group = change.data() as Group
|
|
const { eventId } = context
|
|
|
|
const groupCreator = await getUser(group.creatorId)
|
|
if (!groupCreator) throw new Error('Could not find group creator')
|
|
// create notifications for all members of the group
|
|
await createNotification(
|
|
group.id,
|
|
'group',
|
|
'created',
|
|
groupCreator,
|
|
eventId,
|
|
group.about,
|
|
{
|
|
recipients: group.memberIds,
|
|
slug: group.slug,
|
|
title: group.name,
|
|
}
|
|
)
|
|
})
|