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

POST /subscription/ does not insert correctly #16

Closed
AydanPirani opened this issue Apr 12, 2024 · 0 comments · Fixed by #17
Closed

POST /subscription/ does not insert correctly #16

AydanPirani opened this issue Apr 12, 2024 · 0 comments · Fixed by #17
Assignees
Labels
good first issue Good for newcomers

Comments

@AydanPirani
Copy link
Contributor

AydanPirani commented Apr 12, 2024

Context

The Underlying Issue:
The original code had a document-based database (mongoDB) implemented as such - one document for each subscription entry, which contained a mailingList and an email. To make queries easier, we don't want one database document for each entry but instead per mailing list.

The Fix:
In PR #7 , we decided to instead add pushToSet in the update function whenever a user subscribes - this updates the original collection (associated with the mailingList), and adds the email address. This also ensures that no user duplicates are added to the same mailingList, since Mongo automatically deduplicates the data.

Bug

The Issue:
Our subscription-schema.ts file doesn't have support for an list of emails - just a string per email. Therefore, when we try to insert it/update the array, it doesn't work. To make this more challenging, the current SubscriptionValidator is also used before insertions to the database - this means that we need an entirely new validator.

The Proposed Solution:

  1. Rename the SubscriptionValidator to something like SubscriptionSchemaValidator, and change the import (in database.ts)
  2. Add a new validator named SubscriptionValidator, for input requests - this validator should contain a similar schema to the current SubscriptionValidator.
  3. Add an array field to the database (string array), and remove the email field.

Expected Behavior

By the end of it all, we should have 2 validators:

SubscriptionValidator -> checks for mailingList (string) + email (string), we use it to parse incoming POST requests in the router
SubscriptionSchemaValidator -> checks for mailingList (string) + email list (string[]), we use it when inserting into the Mongoose database (see database.ts)

@AydanPirani AydanPirani added the good first issue Good for newcomers label Apr 12, 2024
@divyack2 divyack2 self-assigned this Apr 12, 2024
@AydanPirani AydanPirani linked a pull request Apr 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants