diff --git a/functions/src/unsubscribe.ts b/functions/src/unsubscribe.ts index 29ede67e..c6edee92 100644 --- a/functions/src/unsubscribe.ts +++ b/functions/src/unsubscribe.ts @@ -7,8 +7,18 @@ import { PrivateUser } from '../../common/user' export const unsubscribe = functions .runWith({ minInstances: 1 }) .https.onRequest(async (req, res) => { - const { id, type } = req.query as { id: string; type: string } - if (!id || !type) return + let { id, type } = req.query as { id: string; type: string } + if (!id || !type) { + res.status(400).send('Empty id or type parameter.') + return + } + + if (type === 'market-resolved') type = 'market-resolve' + + if (!['market-resolve', 'market-comment', 'market-answer'].includes(type)) { + res.status(400).send('Invalid type parameter.') + return + } const user = await getUser(id) @@ -16,7 +26,7 @@ export const unsubscribe = functions const { name } = user const update: Partial = { - ...((type === 'market-resolve' || type === 'market-resolved') && { + ...(type === 'market-resolve' && { unsubscribedFromResolutionEmails: true, }), ...(type === 'market-comment' && {