Repository navigation
Conversation
the same subject, exam, slot and year could be requested any number of times, each one a new row. a unique index on those four fields and an upsert in createPaperRequest keep one row per paper, and a repeat request gets a 200 saying it was already requested instead of a 201 the body is now checked with zod before it reaches the database, so bad json, null, or a field that is not a string returns 400 instead of 500. exam has to be one of the six exam types, which PaperRequest now also enforces, before this an unknown exam like "midterm" was saved refs CodeChefVIT#550
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #550
duplicates
validation
tested against an in-memory mongodb by calling the route directly: repeat and padded-subject requests store one row, 20 identical requests sent at once give one 201 and one row, and every bad body above gets 400. on staging the same requests gave 201s for duplicates and unknown exams and 500s for non-string fields and bad json
before deploying: if the db already has duplicate requests, the unique index won't build until they're removed. the route still works and still dedupes in the meantime, mongoose just logs the failed index build. this keeps the oldest of each and removes the rest:
db.paperrequests.aggregate([
{ $sort: { createdAt: 1 } },
{ $group: { _id: { subject: "$subject", exam: "$exam", slot: "$slot", year: "$year" }, ids: { $push: "$_id" } } },
{ $match: { "ids.1": { $exists: true } } }
]).forEach(group => db.paperrequests.deleteMany({ _id: { $in: group.ids.slice(1) } }))