rebus-ink / ink-API

Hobb API Server: backend for the Rebus Reader system
GNU Affero General Public License v3.0
4 stars 5 forks source link

Turning a source into a reference #612

Closed Marie000 closed 4 years ago

Marie000 commented 4 years ago

This adds an optional query parameter to the delete source route: DELETE /sources/:id?reference=true

This will modify the source to add a 'referenced' timestamp and remove data that is stored in 'links', 'resources', 'readingOrder' Eventually we should probably make it delete the actual content files (for normal deletes too, of course)

When you are getting the library, 'referenced' sources will not show up. You also cannot fetch them individually. However, when you get the notes (either individually or in the /notes endpoint), it will include the source information.

In doing that, I noticed that we were not actually getting the source information when fetching the notes individually. That is fixed.

I also noticed that when a source is soft-deleted, its id will still show up in the Note.sourceId I tried to fix this, but there seems to be a weird bug with knex or objection (either that, or something I don't understand about sql) and I am not able to update a foreign key to null. The sourceId will disappear once we run the hardDelete. My suggestion to fix this would be to remove the sourceId. It is not necessary at all, since we are actually loading the source object before returning the note. In fact, any time we have are eager loading something from a foreign key, we can probably remove the foreign key before returning the object. Makes sense?

Anothe rimportant note: this pull request contains the first ever proper migration that does not involve resetting the database. Hopefully it wont break everything. :crossed_fingers: