refactor createNotif - put ?: args in object (#681)

This commit is contained in:
Sinclair Chen 2022-07-21 17:08:09 -07:00 committed by GitHub
parent cded3f50ff
commit 4b4734531f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 31 deletions

View File

@ -29,12 +29,22 @@ export const createNotification = async (
sourceUser: User, sourceUser: User,
idempotencyKey: string, idempotencyKey: string,
sourceText: string, sourceText: string,
sourceContract?: Contract, miscData?: {
relatedSourceType?: notification_source_types, contract?: Contract
relatedUserId?: string, relatedSourceType?: notification_source_types
sourceSlug?: string, relatedUserId?: string
sourceTitle?: string slug?: string
title?: string
}
) => { ) => {
const {
contract: sourceContract,
relatedSourceType,
relatedUserId,
slug,
title,
} = miscData ?? {}
const shouldGetNotification = ( const shouldGetNotification = (
userId: string, userId: string,
userToReasonTexts: user_to_reason_texts userToReasonTexts: user_to_reason_texts
@ -70,8 +80,8 @@ export const createNotification = async (
sourceContractCreatorUsername: sourceContract?.creatorUsername, sourceContractCreatorUsername: sourceContract?.creatorUsername,
sourceContractTitle: sourceContract?.question, sourceContractTitle: sourceContract?.question,
sourceContractSlug: sourceContract?.slug, sourceContractSlug: sourceContract?.slug,
sourceSlug: sourceSlug ? sourceSlug : sourceContract?.slug, sourceSlug: slug ? slug : sourceContract?.slug,
sourceTitle: sourceTitle ? sourceTitle : sourceContract?.question, sourceTitle: title ? title : sourceContract?.question,
} }
await notificationRef.set(removeUndefinedProps(notification)) await notificationRef.set(removeUndefinedProps(notification))
}) })

View File

@ -64,7 +64,7 @@ async function sendMarketCloseEmails() {
user, user,
'closed' + contract.id.slice(6, contract.id.length), 'closed' + contract.id.slice(6, contract.id.length),
contract.closeTime?.toString() ?? new Date().toString(), contract.closeTime?.toString() ?? new Date().toString(),
contract { contract }
) )
} }
} }

View File

@ -28,6 +28,6 @@ export const onCreateAnswer = functions.firestore
answerCreator, answerCreator,
eventId, eventId,
answer.text, answer.text,
contract { contract }
) )
}) })

View File

@ -134,12 +134,11 @@ const updateUniqueBettorsAndGiveCreatorBonus = async (
fromUser, fromUser,
eventId + '-bonus', eventId + '-bonus',
result.txn.amount + '', result.txn.amount + '',
contract, {
undefined, contract,
// No need to set the user id, we'll use the contract creator id slug: contract.slug,
undefined, title: contract.question,
contract.slug, }
contract.question
) )
} }
} }

View File

@ -68,7 +68,7 @@ export const onCreateCommentOnContract = functions
? 'answer' ? 'answer'
: undefined : undefined
const relatedUser = comment.replyToCommentId const relatedUserId = comment.replyToCommentId
? comments.find((c) => c.id === comment.replyToCommentId)?.userId ? comments.find((c) => c.id === comment.replyToCommentId)?.userId
: answer?.userId : answer?.userId
@ -79,9 +79,7 @@ export const onCreateCommentOnContract = functions
commentCreator, commentCreator,
eventId, eventId,
comment.text, comment.text,
contract, { contract, relatedSourceType, relatedUserId }
relatedSourceType,
relatedUser
) )
const recipientUserIds = uniq([ const recipientUserIds = uniq([

View File

@ -21,6 +21,6 @@ export const onCreateContract = functions.firestore
contractCreator, contractCreator,
eventId, eventId,
richTextToString(contract.description as JSONContent), richTextToString(contract.description as JSONContent),
contract { contract }
) )
}) })

View File

@ -20,11 +20,11 @@ export const onCreateGroup = functions.firestore
groupCreator, groupCreator,
eventId, eventId,
group.about, group.about,
undefined, {
undefined, relatedUserId: memberId,
memberId, slug: group.slug,
group.slug, title: group.name,
group.name }
) )
} }
}) })

View File

@ -26,6 +26,6 @@ export const onCreateLiquidityProvision = functions.firestore
liquidityProvider, liquidityProvider,
eventId, eventId,
liquidity.amount.toString(), liquidity.amount.toString(),
contract { contract }
) )
}) })

View File

@ -30,9 +30,7 @@ export const onFollowUser = functions.firestore
followingUser, followingUser,
eventId, eventId,
'', '',
undefined, { relatedUserId: follow.userId }
undefined,
follow.userId
) )
}) })

View File

@ -36,7 +36,7 @@ export const onUpdateContract = functions.firestore
contractUpdater, contractUpdater,
eventId, eventId,
resolutionText, resolutionText,
contract { contract }
) )
} else if ( } else if (
previousValue.closeTime !== contract.closeTime || previousValue.closeTime !== contract.closeTime ||
@ -62,7 +62,7 @@ export const onUpdateContract = functions.firestore
contractUpdater, contractUpdater,
eventId, eventId,
sourceText, sourceText,
contract { contract }
) )
} }
}) })