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,
|
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))
|
||||||
})
|
})
|
||||||
|
|
|
@ -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 }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,6 @@ export const onCreateAnswer = functions.firestore
|
||||||
answerCreator,
|
answerCreator,
|
||||||
eventId,
|
eventId,
|
||||||
answer.text,
|
answer.text,
|
||||||
contract
|
{ contract }
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -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
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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([
|
||||||
|
|
|
@ -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 }
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -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
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -26,6 +26,6 @@ export const onCreateLiquidityProvision = functions.firestore
|
||||||
liquidityProvider,
|
liquidityProvider,
|
||||||
eventId,
|
eventId,
|
||||||
liquidity.amount.toString(),
|
liquidity.amount.toString(),
|
||||||
contract
|
{ contract }
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -30,9 +30,7 @@ export const onFollowUser = functions.firestore
|
||||||
followingUser,
|
followingUser,
|
||||||
eventId,
|
eventId,
|
||||||
'',
|
'',
|
||||||
undefined,
|
{ relatedUserId: follow.userId }
|
||||||
undefined,
|
|
||||||
follow.userId
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -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 }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user