mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(database): ♻️ Move Applications to our custom ORM
This commit is contained in:
parent
e8827bccfa
commit
9e96eca032
23 changed files with 424 additions and 381 deletions
|
|
@ -1,36 +0,0 @@
|
|||
import type { Application as APIApplication } from "@versia/client/types";
|
||||
import type { InferSelectModel } from "drizzle-orm";
|
||||
import { db } from "~/drizzle/db";
|
||||
import type { Applications } from "~/drizzle/schema";
|
||||
|
||||
export type Application = InferSelectModel<typeof Applications>;
|
||||
|
||||
/**
|
||||
* Retrieves the application associated with the given access token.
|
||||
* @param token The access token to retrieve the application for.
|
||||
* @returns The application associated with the given access token, or null if no such application exists.
|
||||
*/
|
||||
export const getFromToken = async (
|
||||
token: string,
|
||||
): Promise<Application | null> => {
|
||||
const result = await db.query.Tokens.findFirst({
|
||||
where: (tokens, { eq }) => eq(tokens.accessToken, token),
|
||||
with: {
|
||||
application: true,
|
||||
},
|
||||
});
|
||||
|
||||
return result?.application || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this application to an API application.
|
||||
* @returns The API application representation of this application.
|
||||
*/
|
||||
export const applicationToApi = (app: Application): APIApplication => {
|
||||
return {
|
||||
name: app.name,
|
||||
website: app.website,
|
||||
vapid_key: app.vapidKey,
|
||||
};
|
||||
};
|
||||
|
|
@ -32,9 +32,9 @@ import {
|
|||
Users,
|
||||
} from "~/drizzle/schema";
|
||||
import { config } from "~/packages/config-manager/index.ts";
|
||||
import type { ApplicationType } from "~/packages/database-interface/application.ts";
|
||||
import type { EmojiWithInstance } from "~/packages/database-interface/emoji";
|
||||
import { User } from "~/packages/database-interface/user";
|
||||
import type { Application } from "./application.ts";
|
||||
import {
|
||||
type UserWithInstance,
|
||||
type UserWithRelations,
|
||||
|
|
@ -53,7 +53,7 @@ export type StatusWithRelations = Status & {
|
|||
emojis: EmojiWithInstance[];
|
||||
reply: Status | null;
|
||||
quote: Status | null;
|
||||
application: Application | null;
|
||||
application: ApplicationType | null;
|
||||
reblogCount: number;
|
||||
likeCount: number;
|
||||
replyCount: number;
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ import {
|
|||
Tokens,
|
||||
type Users,
|
||||
} from "~/drizzle/schema";
|
||||
import type { ApplicationType } from "~/packages/database-interface/application.ts";
|
||||
import type { EmojiWithInstance } from "~/packages/database-interface/emoji";
|
||||
import { User } from "~/packages/database-interface/user";
|
||||
import type { Application } from "./application.ts";
|
||||
import type { Token } from "./token.ts";
|
||||
|
||||
export type UserType = InferSelectModel<typeof Users>;
|
||||
|
|
@ -99,7 +99,7 @@ export const userExtrasTemplate = (name: string) => ({
|
|||
export interface AuthData {
|
||||
user: User | null;
|
||||
token: string;
|
||||
application: Application | null;
|
||||
application: ApplicationType | null;
|
||||
}
|
||||
|
||||
export const getFromHeader = async (value: string): Promise<AuthData> => {
|
||||
|
|
@ -216,7 +216,7 @@ export const retrieveUserAndApplicationFromToken = async (
|
|||
accessToken: string,
|
||||
): Promise<{
|
||||
user: User | null;
|
||||
application: Application | null;
|
||||
application: ApplicationType | null;
|
||||
}> => {
|
||||
if (!accessToken) {
|
||||
return { user: null, application: null };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue