Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1603/endpoint to check if user email exists #1604

Merged
merged 7 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions server/src/subscriber/subscriber.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,46 @@ export class SubscriberController {
});
return;
}

@Get("/subscribers/email/:email")
async getEmail(@Param() params, @Res() response) {
if (!validateEmail(params.email)) {
response.status(400).send({
error: "Invalid email address."
})
return;
}

const existingUser = await this.subscriberService.findByEmail(params.email);
if (existingUser.code === 404) {
response.status(404).send({
error: "User not found."
})
return;
}

const userExistsInCurrentList = existingUser['1'].result[params.email].contact.list_ids.includes(this.list);
const existingUserListConfirmed = existingUser['1'].result[params.email].contact.custom_fields[`zap_${this.sendgridEnvironment}_confirmed`];

if (userExistsInCurrentList && existingUserListConfirmed) {
response.status(201).send({
pratishta marked this conversation as resolved.
Show resolved Hide resolved
confirmed: true,
message: "User already subscribed."
})
return;
}

if (existingUserListConfirmed === 0) {
response.status(201).send({
confirmed: false,
message: "User is subscribed but must confirm."
})
return;
}

response.status(404).send({
error: "Not found."
})
return;
}
}
Loading