refactor createNotif - put ?: args in object (#681)
This commit is contained in:
parent
cded3f50ff
commit
4b4734531f
|
@ -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))
|
||||
})
|
||||
|
|
|
@ -64,7 +64,7 @@ async function sendMarketCloseEmails() {
|
|||
user,
|
||||
'closed' + contract.id.slice(6, contract.id.length),
|
||||
contract.closeTime?.toString() ?? new Date().toString(),
|
||||
contract
|
||||
{ contract }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,6 @@ export const onCreateAnswer = functions.firestore
|
|||
answerCreator,
|
||||
eventId,
|
||||
answer.text,
|
||||
contract
|
||||
{ contract }
|
||||
)
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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([
|
||||
|
|
|
@ -21,6 +21,6 @@ export const onCreateContract = functions.firestore
|
|||
contractCreator,
|
||||
eventId,
|
||||
richTextToString(contract.description as JSONContent),
|
||||
contract
|
||||
{ contract }
|
||||
)
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -26,6 +26,6 @@ export const onCreateLiquidityProvision = functions.firestore
|
|||
liquidityProvider,
|
||||
eventId,
|
||||
liquidity.amount.toString(),
|
||||
contract
|
||||
{ contract }
|
||||
)
|
||||
})
|
||||
|
|
|
@ -30,9 +30,7 @@ export const onFollowUser = functions.firestore
|
|||
followingUser,
|
||||
eventId,
|
||||
'',
|
||||
undefined,
|
||||
undefined,
|
||||
follow.userId
|
||||
{ relatedUserId: follow.userId }
|
||||
)
|
||||
})
|
||||
|
||||
|
|
|
@ -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 }
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user