diff --git a/src/lib/responseBuilders.ts b/src/lib/responseBuilders.ts index 4bba2a8..105857f 100644 --- a/src/lib/responseBuilders.ts +++ b/src/lib/responseBuilders.ts @@ -1,20 +1,12 @@ import stringify from "json-stable-stringify"; import objectHash from "object-hash"; +import { guilds, matches, tpMessages } from "~/drizzle/schema"; +import { ExtractDataTypes, GetColumns } from "~/types/db"; export const buildMatches = ( - matches: { - id: number; - messageId: number; - guildId: number; - channelId: number; - createrId: number; - roleId: number; - matchType: string; - opponentName: string; - utc_ts: Date; - }[], + queryMatches: ExtractDataTypes>[], ) => - matches.map( + queryMatches.map( // eslint-disable-next-line @typescript-eslint/no-unused-vars ({ id, guildId, utc_ts, ...match }) => ({ ...match, @@ -22,32 +14,12 @@ export const buildMatches = ( }), ); -export function buildConfig(guildQuery: { - id: number; - timezone: string; - tpEnabled: boolean; - tpChannelId: number | null; - tpInterval: number; - tpRoles: boolean; - isAvailableRoleId: number | null; - wantsToBeNotifieRoledId: number | null; - tpMessages: { - messageId: number | null; - day: number; - guildId: number; - }[]; - matches: { - id: number; - messageId: number; - guildId: number; - channelId: number; - createrId: number; - roleId: number; - matchType: string; - opponentName: string; - utc_ts: Date; - }[]; -}) { +export function buildConfig( + guildQuery: ExtractDataTypes> & { + tpMessages: ExtractDataTypes>[]; + matches: ExtractDataTypes>[]; + }, +) { const { id, timezone, diff --git a/src/types/db.d.ts b/src/types/db.d.ts new file mode 100644 index 0000000..bb6a905 --- /dev/null +++ b/src/types/db.d.ts @@ -0,0 +1,11 @@ +import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core"; + +export type GetColumns = + T extends PgTableWithColumns ? Table["columns"] : never; + +export type ExtractDataTypes = { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [K in keyof T]: T[K] extends PgColumn + ? ColumnConfig["data"] + : unknown; +}; diff --git a/src/types/lucia-auth.d.ts b/src/types/lucia-auth.d.ts index aea0005..880f727 100644 --- a/src/types/lucia-auth.d.ts +++ b/src/types/lucia-auth.d.ts @@ -1,6 +1,6 @@ -import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core"; import { users } from "~/drizzle/schema"; import { lucia } from "~/lib/auth"; +import { ExtractDataTypes, GetColumns } from "./db"; declare module "lucia" { // eslint-disable-next-line no-unused-vars @@ -10,15 +10,6 @@ declare module "lucia" { } } -type GetColumns = - T extends PgTableWithColumns ? First["columns"] : never; - -type ExtractDataTypes = { - [K in keyof T]: T[K] extends PgColumn - ? DataType["data"] - : never; -}; - interface DatabaseUserAttributes extends ExtractDataTypes> { warst: string;