-
Notifications
You must be signed in to change notification settings - Fork 0
feat(api): wine lists, top 4 favourites and a demo user (#71) #88
Conversation
|
One test failed when running npm run check, created a separate issue for it #89 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally with a test database: all 143 tests pass, including the 19 list tests and the demo user. npm run check is green.
This is solid work. A few things I noticed while reading:
Keyset cursors on the row id, with the range check against the largest integer, fixes a real 500 and makes paging stable while a list changes. Good.
FOR NO KEY UPDATE before replacing the top 4 closes a race on the unique index that is easy to miss, and clearing the positions first avoids colliding with the old ones.
Checking the constraint name to tell an unknown wine from a deleted user is much better than guessing from the error code alone.
Two questions, neither blocking:
The rule only goes one way: «Har prøvd» removes the wine from «Vil prøve», but nothing stops putting a tried wine back on «Vil prøve», so it can be on both lists. Is that deliberate? It may well be right, since you can want to taste something again, but worth being a choice rather than an accident.
The demo user is in the README with its password. That makes sense for the evaluation, but on the VM it is a real account anyone with the link can log into and change, and the lists are public. Worth saying in the README that npm run db:seed:demo resets it if a reviewer leaves it in a strange state.
One small thing for the description: it says to run npm run db:migrate for the test database too, but not how. I needed DATABASE_URL=... npx node-pg-migrate up to get there. Worth a line in docs/api.md under Database tests.
Thanks! On the questions:
Fixed in #72 . |
Closes #71. Continuation of #65.
What
Backend for the profile lists: favourites with a top 4, «Vil prøve» and «Har prøvd», stored per user and public. Also fixes the backend review comments on #65, and adds a demo user for the evaluation.
user_wine: one row per user, list and wine, withtop_position(1–4) on favourites. Constraints: once per list, positions 1–4 and unique per user, and only favourites can have a position. Indexes for the list pages and formyLists.setWineInList(wineId, list, inList): adds or removes; doing it twice changes nothing. «Har prøvd» takes the wine off «Vil prøve». Returns the wine, somyListsupdates in the Apollo cache.setTopFavourites(wineIds): replaces the whole top 4 in the given order ([]clears it). At most four, each once, all favourites; otherwiseBAD_USER_INPUT, and the old top 4 is kept. Returns the user.User.wines(list, first, after): newest first, keyset cursors on the row id, so pages neither skip nor repeat when the list changes.User.topFavourites: in the chosen order. A wine taken off the favourites leaves the top 4, and the others keep their order.Wine.myLists: a DataLoader per user, so a page of 24 wines asks for the lists in one query.[]when logged out.saveReviewnow runs in one transaction and puts the wine on «Har prøvd». Deleting the review keeps it there.npm run db:seed:democreatesdemo/kork-og-kronewith favourites, a top 4, both other lists and five reviews. Running it again resets the user to the same state.Both mutations call
requireUser(); the user always comes from the session, never from an argument.Review comments from #65 (backend)
23503) gave the wrong message. It now checks the constraint name: an unknown wine givesBAD_USER_INPUT, a deleted user givesUNAUTHENTICATED(db-errors.ts).User.reviewscould skip or repeat reviews while paging, and a hugeaftergave a 500. Both now use keyset cursors on the id with a range check (connection.ts), and the index is now(user_id, id DESC). The offset cursor for the wine search also rejects values too large for the database.The frontend comments from #65 (refetch
MeonUNAUTHENTICATED,clearStore()beforewriteQuery,setWorking(false)infinally) come with the next part #72 .Commits
fix(api): the right message for each foreign keyfix(api): stable paging forUser.reviews, and a range check on cursorsfeat(db): theuser_winetablefeat(api):setWineInList,User.winesandWine.myListschore(backend): Vitest config as.mtsfeat(api): top 4 favouritesfeat(api): a saved review marks the wine as triedfeat(db): the demo userdocs: wine lists, the top 4 and the demo userTests
lists/lists-api.db.test.ts: through Apollo Server against PostgreSQL: login required, the list rules, users kept apart, unknown wines and lists, paging without skipping, onemyListsquery for a page of 24, the top 4 rules and order, two top 4 changes at once, the database constraints, and reviews marking wines as tried.demo/demo-user.db.test.ts: the documented password works, the data follows the rules, averages are updated, and running it again gives the same state.connection.test.ts,db-errors.test.ts,wine-query.test.ts,review-api.db.test.ts: cursors, foreign key errors, and paging while a review is edited.Run with the test database (see Database tests):
Also tested by hand with curl, following docs/manual-testing.md sections 5 and 6.
How to review
npm run db:migrate(both your own and the test database), thennpm run db:seed:demo.localhost:3001/graphqlafter logging in asdemo.After merge (VM)
cd backend npm ci npm run db:migrate npm run db:seed:demoThen restart the backend. Without this, the demo user in the README does not exist on the VM.
Not in this PR