|
4 | 4 | * Delete operations for RERUM v1 |
5 | 5 | * @author Claude Sonnet 4, cubap, thehabes |
6 | 6 | */ |
7 | | -import { newID, isValidID, db } from '../database/index.js' |
| 7 | +import { db } from '../database/index.js' |
8 | 8 | import utils from '../utils.js' |
9 | 9 | import { getAgentClaim, parseDocumentID, getAllVersions, getAllDescendants } from './utils.js' |
10 | 10 |
|
11 | 11 | /** |
12 | 12 | * 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 | + */ |
23 | 19 | const deleteObj = async function(req, res, next) { |
24 | | - let id |
| 20 | + const id = req.params["_id"] |
25 | 21 | 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)) |
30 | 26 | } |
31 | 27 | let agentRequestingDelete = getAgentClaim(req, next) |
32 | 28 | if (!agentRequestingDelete) return |
|
0 commit comments