Skip to content

Commit 0aa5537

Browse files
habesoftware-claude-connector[bot]HabeSoftware Rockin' Botthehabes
authored
Update /delete controller expectations (#263)
* thehabes-work: implement #257 Generated via Full Stack Developer by HabeSoftware * get this through * Get this through --------- Co-authored-by: HabeSoftware Rockin' Bot <habes@habesoftware.rocks> Co-authored-by: Bryan Haberberger <bryan.j.haberberger@slu.edu>
1 parent f7607a2 commit 0aa5537

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

controllers/delete.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,25 @@
44
* Delete operations for RERUM v1
55
* @author Claude Sonnet 4, cubap, thehabes
66
*/
7-
import { newID, isValidID, db } from '../database/index.js'
7+
import { db } from '../database/index.js'
88
import utils from '../utils.js'
99
import { getAgentClaim, parseDocumentID, getAllVersions, getAllDescendants } from './utils.js'
1010

1111
/**
1212
* Mark an object as deleted in the database.
13-
* Support /v1/delete/{id}. Note this is not v1/api/delete, that is not possible (XHR does not support DELETE with body)
14-
* Note /v1/delete/{blank} does not route here. It routes to the generic 404.
15-
* Respond RESTfully
16-
*
17-
* The user may be trying to call /delete and pass in the obj in the body. XHR does not support bodies in delete.
18-
* If there is no id parameter, this is a 400
19-
*
20-
* If there is an id parameter, we ignore body, and continue with that id
21-
*
22-
* */
13+
* Support DELETE /v1/api/delete/:_id.
14+
* Also handles DELETE /v1/api/delete/ (no ID) with a 400 response.
15+
* DELETE requests do not carry a body (XHR does not support DELETE with body),
16+
* so the ID must come from the route parameter.
17+
* Respond RESTfully.
18+
*/
2319
const deleteObj = async function(req, res, next) {
24-
let id
20+
const id = req.params["_id"]
2521
let err = { message: `` }
26-
try {
27-
id = req.params["_id"] ?? parseDocumentID(JSON.parse(JSON.stringify(req.body))["@id"]) ?? parseDocumentID(JSON.parse(JSON.stringify(req.body))["id"])
28-
} catch(error){
29-
return next(utils.createExpressError(error))
22+
if (!id) {
23+
err.message = "The object's id is required in the URL. DELETE does not support request bodies."
24+
err.status = 400
25+
return next(utils.createExpressError(err))
3026
}
3127
let agentRequestingDelete = getAgentClaim(req, next)
3228
if (!agentRequestingDelete) return

0 commit comments

Comments
 (0)