37c7f909a3
* Revert "Revert "Notifications ux fixes - wip (#383)""
This reverts commit 699b03eb42
.
* Group & provide more control over notification display
* UI/UX improvements
* Remove unused text key
* Refactor
* Refactor
* Show answer resolution in notification
* Disable eslint on single linefor exhaustive deps
* Handle arbritrary notifications
* Refactor
* Remove unused vars
* Add follow user
* Various UX improvements, add follow notif
* Various small ui changes
* Show notification settings breakdown
* Improve notification status lines
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import * as functions from 'firebase-functions'
|
|
import { getUser } from './utils'
|
|
import { createNotification } from './create-notification'
|
|
import { Contract } from '../../common/contract'
|
|
|
|
export const onUpdateContract = functions.firestore
|
|
.document('contracts/{contractId}')
|
|
.onUpdate(async (change, context) => {
|
|
const contract = change.after.data() as Contract
|
|
const { eventId } = context
|
|
|
|
const contractUpdater = await getUser(contract.creatorId)
|
|
if (!contractUpdater) throw new Error('Could not find contract updater')
|
|
|
|
const previousValue = change.before.data() as Contract
|
|
if (previousValue.isResolved !== contract.isResolved) {
|
|
await createNotification(
|
|
contract.id,
|
|
'contract',
|
|
'resolved',
|
|
contractUpdater,
|
|
eventId,
|
|
contract
|
|
)
|
|
} else if (
|
|
previousValue.closeTime !== contract.closeTime ||
|
|
previousValue.description !== contract.description
|
|
) {
|
|
await createNotification(
|
|
contract.id,
|
|
'contract',
|
|
'updated',
|
|
contractUpdater,
|
|
eventId,
|
|
contract
|
|
)
|
|
}
|
|
})
|