Skip to content

Conversation

ejscheepers
Copy link
Contributor

The https://api.useplunk.com/v1/track api route was not unsubscribing contacts if they are currently subscribed.

Fixed .env.example for database connection to work when contributing.

Added a line in contributing doc for yarn install.

Copy link
Member

@driaug driaug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor change requested.

Once that is done, you may bump the version in the main package.json to 1.0.8 and I will merge it in!

contact = await prisma.contact.create({
data: {
email,
subscribed: subscribed ?? true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is breaking behaviour. If a contact is first created, it should be put on subscribed unless explicitly mentioned otherwise

if (subscribed !== undefined && contact.subscribed !== subscribed) {
contact = await prisma.contact.update({
where: { id: contact.id },
data: { subscribed },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that Prisma does not complain about subscribed possibly being null here?

Copy link
Contributor Author

@ejscheepers ejscheepers Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, made a fix now. If subscribed is null, then defaults to true.

Could you just double check, do you want nothing to happen when subscribed is undefined?

Copy link
Member

@driaug driaug Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just gave it a quick go myself.

This is what you are looking for, and will work just fine! I'm pretty sure it will only be undefined if someone explicitly passes in that value. If no subscribed is passed then we can just null-check.

      if (subscribed !== null && contact.subscribed !== subscribed) {
        contact = await prisma.contact.update({where: {id: contact.id}, data: {subscribed}});

        redis.del(Keys.Contact.id(contact.id));
        redis.del(Keys.Contact.email(project.id, contact.email));
      }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your patience. Only my 2nd contribution ever.

Was struggling and thought it was a bug in my code until I realised nothing I do makes a difference. Haha.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for contributing. Don't worry about making mistakes, I make them all the time :)

@driaug driaug merged commit 1126c18 into useplunk:main Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants