added bulk updates to data controller

This commit is contained in:
dswbx
2025-02-26 18:04:07 +01:00
parent 4d75cfe0ea
commit 4a2dbf8f79
9 changed files with 285 additions and 240 deletions

View File

@@ -1,7 +1,21 @@
import { Hono } from "hono";
import type { ServerEnv } from "modules/Module";
import type { App } from "App";
import { type Context, Hono } from "hono";
import * as middlewares from "modules/middlewares";
export type ServerEnv = {
Variables: {
app: App;
// to prevent resolving auth multiple times
auth?: {
resolved: boolean;
registered: boolean;
skip: boolean;
user?: { id: any; role?: string; [key: string]: any };
};
html?: string;
};
};
export class Controller {
protected middlewares = middlewares;
@@ -16,4 +30,19 @@ export class Controller {
getController(): Hono<ServerEnv> {
return this.create();
}
protected isJsonRequest(c: Context<ServerEnv>) {
return (
c.req.header("Content-Type") === "application/json" ||
c.req.header("Accept") === "application/json"
);
}
protected notFound(c: Context<ServerEnv>) {
if (this.isJsonRequest(c)) {
return c.json({ error: "Not found" }, 404);
}
return c.notFound();
}
}