feat(shared): reorder AppError constructor to (message, code, status), add singleton logger, retry and TTL cache utilities
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
import type { NextFunction, Request, Response } from "express";
|
||||
import { createChildLogger } from "../../shared/logger/index.js";
|
||||
import { asyncHandler } from "../../shared/middlewares/index.js";
|
||||
import { createChildLogger } from "@bete/shared/logger";
|
||||
import {
|
||||
asyncHandler,
|
||||
requireParam,
|
||||
} from "../../shared/middlewares/index.js";
|
||||
import { analyticsQuerySchema } from "./analytics.schema.js";
|
||||
import { analyticsService } from "./analytics.service.js";
|
||||
|
||||
const logger = createChildLogger("analytics.controller");
|
||||
|
||||
function requireQueryString(value: unknown, name: string): string {
|
||||
if (typeof value !== "string" || value.length === 0) {
|
||||
throw new Error(`Missing query parameter: ${name}`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function handleGetOverview(
|
||||
req: Request,
|
||||
res: Response,
|
||||
@@ -32,7 +28,7 @@ export function handleGetDailyTrend(
|
||||
next: NextFunction,
|
||||
) {
|
||||
return asyncHandler(async (req: Request, res: Response) => {
|
||||
const guildId = requireQueryString(req.query.guildId, "guildId");
|
||||
const guildId = requireParam(req.query.guildId, "query parameter", "guildId");
|
||||
const hours = req.query.hours ? Number(req.query.hours) : 24;
|
||||
logger.debug({ guildId, hours }, "Handling get daily trend");
|
||||
const result = await analyticsService.getDailyTrend(guildId, hours);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getPool } from "../../shared/database/index.js";
|
||||
import { createChildLogger } from "../../shared/logger/index.js";
|
||||
import { createChildLogger } from "@bete/shared/logger";
|
||||
|
||||
const logger = createChildLogger("analytics.repository");
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { ForbiddenError, ValidationError } from "../../shared/errors/index.js";
|
||||
import { createChildLogger } from "../../shared/logger/index.js";
|
||||
import { ForbiddenError, ValidationError } from "@bete/shared/errors";
|
||||
import { createChildLogger } from "@bete/shared/logger";
|
||||
import { analyticsRepository } from "./analytics.repository.js";
|
||||
import type { AnalyticsQuery } from "./analytics.schema.js";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user