Send better error responses for unsubscribe.
This commit is contained in:
parent
d12189ae08
commit
f9b881a017
|
@ -7,8 +7,18 @@ import { PrivateUser } from '../../common/user'
|
||||||
export const unsubscribe = functions
|
export const unsubscribe = functions
|
||||||
.runWith({ minInstances: 1 })
|
.runWith({ minInstances: 1 })
|
||||||
.https.onRequest(async (req, res) => {
|
.https.onRequest(async (req, res) => {
|
||||||
const { id, type } = req.query as { id: string; type: string }
|
let { id, type } = req.query as { id: string; type: string }
|
||||||
if (!id || !type) return
|
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)
|
const user = await getUser(id)
|
||||||
|
|
||||||
|
@ -16,7 +26,7 @@ export const unsubscribe = functions
|
||||||
const { name } = user
|
const { name } = user
|
||||||
|
|
||||||
const update: Partial<PrivateUser> = {
|
const update: Partial<PrivateUser> = {
|
||||||
...((type === 'market-resolve' || type === 'market-resolved') && {
|
...(type === 'market-resolve' && {
|
||||||
unsubscribedFromResolutionEmails: true,
|
unsubscribedFromResolutionEmails: true,
|
||||||
}),
|
}),
|
||||||
...(type === 'market-comment' && {
|
...(type === 'market-comment' && {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user