style: format message query changes
This commit is contained in:
@@ -26,10 +26,7 @@ export function decodeCursor(cursor?: string): CursorData | null {
|
|||||||
if (!cursor) return null;
|
if (!cursor) return null;
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(Buffer.from(cursor, "base64").toString("utf-8"));
|
const data = JSON.parse(Buffer.from(cursor, "base64").toString("utf-8"));
|
||||||
if (
|
if (typeof data.created_at === "number" && typeof data.id === "string") {
|
||||||
typeof data.created_at === "number" &&
|
|
||||||
typeof data.id === "string"
|
|
||||||
) {
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -391,7 +388,9 @@ export async function listMessages(
|
|||||||
|
|
||||||
if (query.status && query.status.length > 0) {
|
if (query.status && query.status.length > 0) {
|
||||||
conditions.push(
|
conditions.push(
|
||||||
or(...query.status.map((status) => eq(messagesTable.ai_status, status))),
|
or(
|
||||||
|
...query.status.map((status) => eq(messagesTable.ai_status, status)),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,7 +426,7 @@ export async function listMessages(
|
|||||||
.limit(fetchLimit);
|
.limit(fetchLimit);
|
||||||
|
|
||||||
const hasMore = rows.length > query.limit;
|
const hasMore = rows.length > query.limit;
|
||||||
const data = (rows.slice(0, query.limit) as MessageRecord[]);
|
const data = rows.slice(0, query.limit) as MessageRecord[];
|
||||||
|
|
||||||
let nextCursor: string | null = null;
|
let nextCursor: string | null = null;
|
||||||
if (hasMore && data.length > 0) {
|
if (hasMore && data.length > 0) {
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ import {
|
|||||||
listMessages,
|
listMessages,
|
||||||
listReviewMessages,
|
listReviewMessages,
|
||||||
} from "../../src/moderation/messageStore";
|
} from "../../src/moderation/messageStore";
|
||||||
import { getDatabase, initializeDatabase, closeDatabase } from "../../src/database/drizzle";
|
import {
|
||||||
|
getDatabase,
|
||||||
|
initializeDatabase,
|
||||||
|
closeDatabase,
|
||||||
|
} from "../../src/database/drizzle";
|
||||||
import { createChildLogger } from "../../src/logger";
|
import { createChildLogger } from "../../src/logger";
|
||||||
import type { MessageRecord } from "../../src/moderation/types";
|
import type { MessageRecord } from "../../src/moderation/types";
|
||||||
|
|
||||||
@@ -15,7 +19,10 @@ const logger = createChildLogger("messageStoreQueries.test");
|
|||||||
describe("message cursor helpers", () => {
|
describe("message cursor helpers", () => {
|
||||||
it("round-trips created_at and id", () => {
|
it("round-trips created_at and id", () => {
|
||||||
const cursor = encodeCursor({ created_at: 1710000000000, id: "abc" });
|
const cursor = encodeCursor({ created_at: 1710000000000, id: "abc" });
|
||||||
expect(decodeCursor(cursor)).toEqual({ created_at: 1710000000000, id: "abc" });
|
expect(decodeCursor(cursor)).toEqual({
|
||||||
|
created_at: 1710000000000,
|
||||||
|
id: "abc",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns null for invalid cursor", () => {
|
it("returns null for invalid cursor", () => {
|
||||||
@@ -56,7 +63,10 @@ describe("message query integration tests", () => {
|
|||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.debug({ error }, "Messages table already exists or error creating it");
|
logger.debug(
|
||||||
|
{ error },
|
||||||
|
"Messages table already exists or error creating it",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -422,7 +432,9 @@ describe("message query integration tests", () => {
|
|||||||
|
|
||||||
expect(result.data).toHaveLength(3);
|
expect(result.data).toHaveLength(3);
|
||||||
const ids = result.data.map((m) => m.id).sort();
|
const ids = result.data.map((m) => m.id).sort();
|
||||||
expect(ids).toEqual(["msg-review-2", "msg-review-3", "msg-review-4"].sort());
|
expect(ids).toEqual(
|
||||||
|
["msg-review-2", "msg-review-3", "msg-review-4"].sort(),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("excludes clean status messages", async () => {
|
it("excludes clean status messages", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user