refactor: large codebase cleanup - consolidate schemas, migrate to Drizzle ORM, extract frontend components, modernize Docker builds
Build & Deploy / build-and-push (discord-gateway) (push) Failing after 2m22s
Build & Deploy / build-and-push (backend) (push) Failing after 3m22s
Build & Deploy / build-and-push (proxy) (push) Successful in 1m36s
Build & Deploy / deploy (push) Skipped
Build & Deploy / build-and-push (discord-gateway) (push) Failing after 2m22s
Build & Deploy / build-and-push (backend) (push) Failing after 3m22s
Build & Deploy / build-and-push (proxy) (push) Successful in 1m36s
Build & Deploy / deploy (push) Skipped
- Consolidate all DB schema definitions into packages/shared as single source of truth - Migrate backend from raw SQL to Drizzle ORM across all modules - Extract frontend inline UI into separate component files - Refactor discord-gateway circuitBreaker into conversationState + moderationState - Convert messageStore to Proxy singleton pattern - Add validateBody/validateQuery middleware + Zod schemas for API endpoints - Modernize Docker builds with multi-stage + pnpm deploy - Migrate CI/CD from deployment to image-based pipeline - Remove 60+ unused/dead files (~15K lines) - Update color scheme from sky-blue to teal-cyan - Move DB connection management to @bete/shared/database Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
63f21513bd
commit
5802d02e29
@@ -1,6 +1,7 @@
|
||||
import { AppError, ValidationError } from "@bete/shared/errors";
|
||||
import { createChildLogger } from "@bete/shared/logger";
|
||||
import type { NextFunction, Request, Response } from "express";
|
||||
import type { ZodSchema } from "zod";
|
||||
|
||||
const logger = createChildLogger("middleware");
|
||||
|
||||
@@ -90,3 +91,49 @@ export function requireParam(
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Express middleware that validates `req.body` against a Zod schema.
|
||||
* On success, replaces `req.body` with the parsed (and defaulted) value.
|
||||
* On failure, responds with 400 and the Zod validation errors.
|
||||
*/
|
||||
export function validateBody<T>(schema: ZodSchema<T>) {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
const result = schema.safeParse(req.body);
|
||||
if (!result.success) {
|
||||
res.status(400).json({
|
||||
error: "VALIDATION_ERROR",
|
||||
message: "Request body validation failed",
|
||||
details: result.error.flatten().fieldErrors,
|
||||
});
|
||||
return;
|
||||
}
|
||||
req.body = result.data;
|
||||
next();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Express middleware that validates `req.query` against a Zod schema.
|
||||
* On success, replaces `req.query` with the parsed (and defaulted) value.
|
||||
* On failure, responds with 400 and the Zod validation errors.
|
||||
*/
|
||||
export function validateQuery<T>(schema: ZodSchema<T>) {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
const result = schema.safeParse(req.query);
|
||||
if (!result.success) {
|
||||
res.status(400).json({
|
||||
error: "VALIDATION_ERROR",
|
||||
message: "Query parameter validation failed",
|
||||
details: result.error.flatten().fieldErrors,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Note: Express req.query is typed as ParsedQs — we attach parsed data
|
||||
// alongside it via a custom property. For route handlers that read req.query
|
||||
// directly, the middleware won't change the type; handlers should opt in by
|
||||
// reading from the validated result or by using the schema's output type.
|
||||
(req as Request & { validatedQuery: T }).validatedQuery = result.data;
|
||||
next();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user