mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(database): 🎨 Refactor note handling into its own class instead of separate functions
This commit is contained in:
parent
2998cb4deb
commit
9081036c6d
36 changed files with 1194 additions and 1215 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { randomBytes } from "node:crypto";
|
||||
import { inArray, like } from "drizzle-orm";
|
||||
import { type Status, findManyStatuses } from "~database/entities/Status";
|
||||
import { asc, inArray, like } from "drizzle-orm";
|
||||
import type { Status } from "~database/entities/Status";
|
||||
import {
|
||||
type User,
|
||||
type UserWithRelations,
|
||||
|
|
@ -9,6 +9,7 @@ import {
|
|||
import { db } from "~drizzle/db";
|
||||
import { status, token, user } from "~drizzle/schema";
|
||||
import { server } from "~index";
|
||||
import { Note } from "~packages/database-interface/note";
|
||||
/**
|
||||
* This allows us to send a test request to the server even when it isnt running
|
||||
* CURRENTLY NOT WORKING, NEEDS TO BE FIXED
|
||||
|
|
@ -86,20 +87,15 @@ export const getTestStatuses = async (
|
|||
const statuses: Status[] = [];
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const newStatus = (
|
||||
await db
|
||||
.insert(status)
|
||||
.values({
|
||||
content: `${i} ${randomBytes(32).toString("hex")}`,
|
||||
authorId: user.id,
|
||||
sensitive: false,
|
||||
updatedAt: new Date().toISOString(),
|
||||
visibility: "public",
|
||||
applicationId: null,
|
||||
...partial,
|
||||
})
|
||||
.returning()
|
||||
)[0];
|
||||
const newStatus = await Note.insert({
|
||||
content: `${i} ${randomBytes(32).toString("hex")}`,
|
||||
authorId: user.id,
|
||||
sensitive: false,
|
||||
updatedAt: new Date().toISOString(),
|
||||
visibility: "public",
|
||||
applicationId: null,
|
||||
...partial,
|
||||
});
|
||||
|
||||
if (!newStatus) {
|
||||
throw new Error("Failed to create test status");
|
||||
|
|
@ -108,14 +104,13 @@ export const getTestStatuses = async (
|
|||
statuses.push(newStatus);
|
||||
}
|
||||
|
||||
const statusesWithRelations = await findManyStatuses({
|
||||
where: (status, { inArray }) =>
|
||||
return (
|
||||
await Note.manyFromSql(
|
||||
inArray(
|
||||
status.id,
|
||||
statuses.map((s) => s.id),
|
||||
),
|
||||
orderBy: (status, { asc }) => asc(status.id),
|
||||
});
|
||||
|
||||
return statusesWithRelations;
|
||||
asc(status.id),
|
||||
)
|
||||
).map((n) => n.getStatus());
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue