fix exisiting users detection

This commit is contained in:
Matthias Kretschmann 2018-10-30 12:52:37 +01:00
parent b9cd283ab6
commit bac7e7c694
Signed by: m
GPG Key ID: 606EEEF3C479A91F
1 changed files with 8 additions and 4 deletions

View File

@ -78,10 +78,12 @@ server.post('/newsletter/:email', (req, res) => {
request.get(baseOptions, (error, response, body) => {
if (error) res.send(error)
const data = JSON.parse(body)
// Member exists and is subscribed
if (body.status === 'subscribed') {
if (data.status === 'subscribed') {
// Patch in native GDPR permissions
addMarketingPermissions(body, () => {
addMarketingPermissions(data, () => {
res.send('{ "status": "exists" }')
})
} else {
@ -89,12 +91,14 @@ server.post('/newsletter/:email', (req, res) => {
request.put(optionsCreate, (error2, response, body2) => {
if (error2) res.send(error2)
if (Number.isInteger(body2.status)) {
const data2 = JSON.parse(body2)
if (Number.isInteger(data2.status)) {
res.send(body2)
}
// Patch in native GDPR permissions
addMarketingPermissions(body2, () => {
addMarketingPermissions(data2, () => {
res.send('{ "status": "created" }')
})
})