Skip to content

An Express router gains a destructive route ​

A user API on Express and Drizzle. The change registers DELETE /users, a bulk delete behind the requireAdmin middleware.

An Express route has no function name of its own, so Aburi names the registration after its method, path and position, and treats it as a Symbol like any other: the report lists it as added, with the middleware in front of it, the database write it performs and the calls it makes. Nothing else in the router moved, and the report says so.

Configuration ​

json
{
  "$schema": "https://aburi.kage1020.com/schema/aburi.config.v1.json",
  "languages": ["@aburi/lang-typescript"],
  "frameworks": ["@aburi/framework-express"],
  "effects": ["@aburi/effects-drizzle"]
}

The change ​

diff
diff --git a/src/routes.ts b/src/routes.ts
index 2023b6a..8b739cf 100644
--- a/src/routes.ts
+++ b/src/routes.ts
@@ -1,4 +1,4 @@
-import { eq } from "drizzle-orm"
+import { eq, inArray } from "drizzle-orm"
 import express from "express"
 import { db, users } from "./db"
 import { requireAdmin } from "./middleware"
@@ -13,3 +13,9 @@ router.get("/users/:id", async (req, res) => {
   const [user] = await db.select().from(users).where(eq(users.id, req.params.id))
   res.json(user ?? null)
 })
+
+router.delete("/users", requireAdmin, async (req, res) => {
+  const ids: string[] = req.body.ids
+  await db.delete(users).where(inArray(users.id, ids))
+  res.status(204).end()
+})

What aburi diff reports ​

Aburi diff: HEAD~1..HEAD ​

Summary: +1 added · -0 removed · ~0 changed · 0 moved · 0 moved+changed

🧵 Slice View ​

Standalone changes ​
1 symbol with no resolved call to or from another symbol in this view
  • router__delete__$users__d0 — new call with db.write · src/routes.ts:17

➕ Added ​

router__delete__$users__d0 (call) ​

File: src/routes.ts:17Middleware: requireAdminEffects:

  • db.write: db.delete (L19) [effects-drizzle]

Calls:

  • db.delete.where (L19)
  • inArray (L19)
  • res.status (L20)
  • res.status.end (L20)

Released under the Apache License 2.0.