style(analytics): reorder imports and apply consistent formatting

This commit is contained in:
MythEclipse
2026-06-03 18:20:27 +07:00
parent b8979cbee1
commit 58f5d4f7ce
4 changed files with 24 additions and 17 deletions
@@ -1,9 +1,6 @@
import type { NextFunction, Request, Response } from "express";
import { createChildLogger } from "@bete/shared/logger";
import {
asyncHandler,
requireParam,
} from "../../shared/middlewares/index.js";
import type { NextFunction, Request, Response } from "express";
import { asyncHandler, requireParam } from "../../shared/middlewares/index.js";
import { analyticsQuerySchema } from "./analytics.schema.js";
import { analyticsService } from "./analytics.service.js";
@@ -28,7 +25,11 @@ export function handleGetDailyTrend(
next: NextFunction,
) {
return asyncHandler(async (req: Request, res: Response) => {
const guildId = requireParam(req.query.guildId, "query parameter", "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 "@bete/shared/logger";
import { getPool } from "../../shared/database/index.js";
const logger = createChildLogger("analytics.repository");
@@ -153,10 +153,7 @@ export class AnalyticsRepository {
hours = 24,
limit = 10,
) {
logger.debug(
{ guildId, channelId, hours, limit },
"Getting top violators",
);
logger.debug({ guildId, channelId, hours, limit }, "Getting top violators");
const pool = getPool();
const filter = buildTimeFilter(guildId, channelId, hours);
@@ -193,7 +190,10 @@ export class AnalyticsRepository {
warned_count: Number(r.warned_count ?? 0),
violation_score: Number(r.violation_score ?? 0),
worst_flags: (r.worst_flags as string | null)
? (r.worst_flags as string).split(",").map((s) => s.trim()).filter(Boolean)
? (r.worst_flags as string)
.split(",")
.map((s) => s.trim())
.filter(Boolean)
: [],
last_violation: Number(r.last_violation ?? 0),
}));
@@ -346,7 +346,10 @@ export class AnalyticsRepository {
hours = 24,
limit = 20,
) {
logger.debug({ guildId, channelId, hours, limit }, "Getting moderation actions");
logger.debug(
{ guildId, channelId, hours, limit },
"Getting moderation actions",
);
const pool = getPool();
const filter = buildTimeFilter(guildId, channelId, hours);
@@ -368,7 +371,7 @@ export class AnalyticsRepository {
m.content
FROM moderation_actions ma
LEFT JOIN messages m ON m.id = ma.message_id
${filter.where.replace('guild_id', 'ma.guild_id').replace('created_at', 'ma.created_at')}
${filter.where.replace("guild_id", "ma.guild_id").replace("created_at", "ma.created_at")}
ORDER BY ma.created_at DESC
LIMIT $${filter.params.length + 1}
`,
@@ -9,8 +9,8 @@ import {
handleGetModerationActions,
handleGetModerationStats,
handleGetOverview,
handleGetTopViolators,
handleGetTopics,
handleGetTopViolators,
handleGetUserLeaderboard,
} from "./analytics.controller.js";
@@ -1,6 +1,6 @@
import { config } from "../../shared/config/index.js";
import { ForbiddenError, ValidationError } from "@bete/shared/errors";
import { createChildLogger } from "@bete/shared/logger";
import { config } from "../../shared/config/index.js";
import { analyticsRepository } from "./analytics.repository.js";
import type { AnalyticsQuery } from "./analytics.schema.js";
@@ -99,7 +99,10 @@ export class AnalyticsService {
limit = 20,
) {
this.assertMonitorGuild(guildId);
logger.debug({ guildId, channelId, hours, limit }, "Getting moderation actions");
logger.debug(
{ guildId, channelId, hours, limit },
"Getting moderation actions",
);
return analyticsRepository.getModerationActions(
guildId,
channelId,