Updating the form action to handle edits
In this section, we’ll continue with updating the repository to handle updating birthdays in addition to adding new ones. We’ll tackle this in three parts: first, replacing items in the db
field, second, guarding against invalid id
values, and third, ensuring that id
values are passed back in validation errors so that the same birthday can be corrected by the user.
Replacing items in the repository
Let’s get started with the test you wrote in the previous section:
- Un-skip the last test you wrote in the
src/routes/birthdays/page.server.test.js
file. Make sure to run the tests and watch it fail, ensuring you’re on Red:it('updates an entry that shares the same id', async () => { ... });
- To make that test pass, start by adding a
replace
function tosrc/lib/server/birthdayRepository.js
:export const replace = (id, item) => db.set(id, { ...item, id });
- Then, import...