style(analytics): reorder imports and apply consistent formatting
This commit is contained in:
@@ -1,9 +1,6 @@
|
|||||||
import type { NextFunction, Request, Response } from "express";
|
|
||||||
import { createChildLogger } from "@bete/shared/logger";
|
import { createChildLogger } from "@bete/shared/logger";
|
||||||
import {
|
import type { NextFunction, Request, Response } from "express";
|
||||||
asyncHandler,
|
import { asyncHandler, requireParam } from "../../shared/middlewares/index.js";
|
||||||
requireParam,
|
|
||||||
} from "../../shared/middlewares/index.js";
|
|
||||||
import { analyticsQuerySchema } from "./analytics.schema.js";
|
import { analyticsQuerySchema } from "./analytics.schema.js";
|
||||||
import { analyticsService } from "./analytics.service.js";
|
import { analyticsService } from "./analytics.service.js";
|
||||||
|
|
||||||
@@ -28,7 +25,11 @@ export function handleGetDailyTrend(
|
|||||||
next: NextFunction,
|
next: NextFunction,
|
||||||
) {
|
) {
|
||||||
return asyncHandler(async (req: Request, res: Response) => {
|
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;
|
const hours = req.query.hours ? Number(req.query.hours) : 24;
|
||||||
logger.debug({ guildId, hours }, "Handling get daily trend");
|
logger.debug({ guildId, hours }, "Handling get daily trend");
|
||||||
const result = await analyticsService.getDailyTrend(guildId, hours);
|
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 { createChildLogger } from "@bete/shared/logger";
|
||||||
|
import { getPool } from "../../shared/database/index.js";
|
||||||
|
|
||||||
const logger = createChildLogger("analytics.repository");
|
const logger = createChildLogger("analytics.repository");
|
||||||
|
|
||||||
@@ -153,10 +153,7 @@ export class AnalyticsRepository {
|
|||||||
hours = 24,
|
hours = 24,
|
||||||
limit = 10,
|
limit = 10,
|
||||||
) {
|
) {
|
||||||
logger.debug(
|
logger.debug({ guildId, channelId, hours, limit }, "Getting top violators");
|
||||||
{ guildId, channelId, hours, limit },
|
|
||||||
"Getting top violators",
|
|
||||||
);
|
|
||||||
const pool = getPool();
|
const pool = getPool();
|
||||||
const filter = buildTimeFilter(guildId, channelId, hours);
|
const filter = buildTimeFilter(guildId, channelId, hours);
|
||||||
|
|
||||||
@@ -193,7 +190,10 @@ export class AnalyticsRepository {
|
|||||||
warned_count: Number(r.warned_count ?? 0),
|
warned_count: Number(r.warned_count ?? 0),
|
||||||
violation_score: Number(r.violation_score ?? 0),
|
violation_score: Number(r.violation_score ?? 0),
|
||||||
worst_flags: (r.worst_flags as string | null)
|
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),
|
last_violation: Number(r.last_violation ?? 0),
|
||||||
}));
|
}));
|
||||||
@@ -346,7 +346,10 @@ export class AnalyticsRepository {
|
|||||||
hours = 24,
|
hours = 24,
|
||||||
limit = 20,
|
limit = 20,
|
||||||
) {
|
) {
|
||||||
logger.debug({ guildId, channelId, hours, limit }, "Getting moderation actions");
|
logger.debug(
|
||||||
|
{ guildId, channelId, hours, limit },
|
||||||
|
"Getting moderation actions",
|
||||||
|
);
|
||||||
const pool = getPool();
|
const pool = getPool();
|
||||||
const filter = buildTimeFilter(guildId, channelId, hours);
|
const filter = buildTimeFilter(guildId, channelId, hours);
|
||||||
|
|
||||||
@@ -368,7 +371,7 @@ export class AnalyticsRepository {
|
|||||||
m.content
|
m.content
|
||||||
FROM moderation_actions ma
|
FROM moderation_actions ma
|
||||||
LEFT JOIN messages m ON m.id = ma.message_id
|
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
|
ORDER BY ma.created_at DESC
|
||||||
LIMIT $${filter.params.length + 1}
|
LIMIT $${filter.params.length + 1}
|
||||||
`,
|
`,
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import {
|
|||||||
handleGetModerationActions,
|
handleGetModerationActions,
|
||||||
handleGetModerationStats,
|
handleGetModerationStats,
|
||||||
handleGetOverview,
|
handleGetOverview,
|
||||||
handleGetTopViolators,
|
|
||||||
handleGetTopics,
|
handleGetTopics,
|
||||||
|
handleGetTopViolators,
|
||||||
handleGetUserLeaderboard,
|
handleGetUserLeaderboard,
|
||||||
} from "./analytics.controller.js";
|
} from "./analytics.controller.js";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { config } from "../../shared/config/index.js";
|
|
||||||
import { ForbiddenError, ValidationError } from "@bete/shared/errors";
|
import { ForbiddenError, ValidationError } from "@bete/shared/errors";
|
||||||
import { createChildLogger } from "@bete/shared/logger";
|
import { createChildLogger } from "@bete/shared/logger";
|
||||||
|
import { config } from "../../shared/config/index.js";
|
||||||
import { analyticsRepository } from "./analytics.repository.js";
|
import { analyticsRepository } from "./analytics.repository.js";
|
||||||
import type { AnalyticsQuery } from "./analytics.schema.js";
|
import type { AnalyticsQuery } from "./analytics.schema.js";
|
||||||
|
|
||||||
@@ -99,7 +99,10 @@ export class AnalyticsService {
|
|||||||
limit = 20,
|
limit = 20,
|
||||||
) {
|
) {
|
||||||
this.assertMonitorGuild(guildId);
|
this.assertMonitorGuild(guildId);
|
||||||
logger.debug({ guildId, channelId, hours, limit }, "Getting moderation actions");
|
logger.debug(
|
||||||
|
{ guildId, channelId, hours, limit },
|
||||||
|
"Getting moderation actions",
|
||||||
|
);
|
||||||
return analyticsRepository.getModerationActions(
|
return analyticsRepository.getModerationActions(
|
||||||
guildId,
|
guildId,
|
||||||
channelId,
|
channelId,
|
||||||
|
|||||||
Reference in New Issue
Block a user