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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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