Fix: Finished Backend

This commit is contained in:
Aron Malcher 2024-02-26 21:46:33 +01:00
parent 6b388729d9
commit ffaf8d989e
Signed by: aronmal
GPG key ID: 816B7707426FC612
30 changed files with 1478 additions and 873 deletions

15
src/types/authjs.d.ts vendored
View file

@ -1,15 +0,0 @@
import { DefaultSession as DSession } from "@auth/core/types"
declare module "@auth/core/types" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session extends DSession {
user?: {
id: string
name?: string | null
email?: string | null
image?: string | null
}
}
}

70
src/types/backend.d.ts vendored Normal file
View file

@ -0,0 +1,70 @@
import { HttpStatus } from "http-status";
import { paths } from "./liljudd";
export type MyPaths = keyof paths;
export type Methods<Path extends MyPaths> = keyof paths[Path];
export type Responses<
Path extends MyPaths,
Method extends Methods<Path>,
> = "responses" extends keyof paths[Path][Method]
? paths[Path][Method]["responses"]
: never;
type StatusCodes<P extends MyPaths, M extends Methods<P>> = {
[CodeName in keyof HttpStatus]: HttpStatus[CodeName] extends number
? HttpStatus[CodeName] extends keyof Responses<P, M>
? CodeName
: never
: never;
}[keyof HttpStatus];
export type ResponseSchemas<
Path extends MyPaths,
Method extends Methods<Path>,
Code extends StatusCodes<Path, Method>,
> = Code extends keyof HttpStatus
? HttpStatus[Code] extends keyof Responses<Path, Method>
? "content" extends keyof Responses<Path, Method>[HttpStatus[Code]]
? "application/json" extends keyof Responses<
Path,
Method
>[HttpStatus[Code]]["content"]
? Responses<
Path,
Method
>[HttpStatus[Code]]["content"]["application/json"] extends never
? null
: Responses<
Path,
Method
>[HttpStatus[Code]]["content"]["application/json"]
: never
: never
: never
: never;
export type Parameters<
Path extends MyPaths,
Method extends Methods<Path>,
> = "parameters" extends keyof paths[Path][Method]
? "path" extends keyof paths[Path][Method]["parameters"]
? paths[Path][Method]["parameters"]["path"]
: never
: never;
export type RequestBody<
Path extends MyPaths,
Method extends Methods<Path>,
> = "requestBody" extends keyof paths[Path][Method]
? "content" extends keyof paths[Path][Method]["requestBody"]
? "application/json" extends keyof paths[Path][Method]["requestBody"]["content"]
? paths[Path][Method]["requestBody"]["content"]["application/json"]
: never
: never
: never;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface APIResponse<Path extends MyPaths, Method extends Methods<Path>>
extends Response {}

1
src/types/global.d.ts vendored Normal file
View file

@ -0,0 +1 @@
/// <reference types="@solidjs/start/env" />

335
src/types/liljudd.d.ts vendored
View file

@ -5,24 +5,48 @@
export interface paths {
"/api/config/{guildId}": {
"/api/boot": {
/**
* Find guild config by ID
* @description Returns a single guild config
* Retrieve all guild's configs
* @description Returns all guild's configs.
*/
get: operations["getGuildsForBoot"];
};
"/api/{guildId}/config": {
/**
* Find a guild's config by ID
* @description Returns a single guild's config.
*/
get: operations["getGuildById"];
/**
* Deletes a guild config by ID
* @description Delete a guild's config
* Deletes a guild's config by ID
* @description Delete a guild's config when the bot is removed from the guild.
*/
delete: operations["deleteGuildById"];
};
"/api/tp_messages/{guildId}": {
"/api/{guildId}/tp_messages": {
/**
* Find guild by ID for it's tp_messages
* Find the tp_messages of guild by ID
* @description Returns tp_messages for a guild
*/
get: operations["getTp_messagesOfGuildById"];
/**
* Put new message IDs for tp_messages of guild by ID
* @description Returns tp_messages for a guild
*/
put: operations["putTp_messagesOfGuildById"];
};
"/api/{guildId}/matches": {
/**
* Find all matches of guild by ID
* @description Returns tp_messages for a guild
*/
get: operations["getMatchesOfGuildById"];
/**
* Save a new created match of guild by ID
* @description Returns tp_messages for a guild
*/
post: operations["postMatchOfGuildById"];
};
}
@ -32,66 +56,124 @@ export interface components {
schemas: {
guildConfig: {
/**
* Format: varchar(19)
* Format: varchar(20)
* @example 1234567890123456789
*/
guildID?: string;
features?: {
time_planning?: {
guildId: string;
/**
* Format: text
* @example Europe/Berlin
*/
timezone: string;
features: {
timePlanning: {
enabled: boolean;
/**
* Format: varchar(19)
* Format: varchar(20)
* @example 1234567890123456789
*/
channelID?: string;
/** @example 0 0 1 * * * 60o 1w */
cron?: string;
/**
* Format: varchar(19)
* @example 1234567890123456789
*/
isAvailableRoleId?: string;
/**
* Format: varchar(19)
* @example 1234567890123456789
*/
wantsToBeNotifieRoledId?: string;
channelId: string | null;
/** @example 0 */
targetMinute: number;
/** @example 1 */
targetHour: number;
/** @example 1 */
targetDay: number;
roles: {
enabled: boolean;
/**
* Format: varchar(20)
* @example 1234567890123456789
*/
isAvailableRoleId: string | null;
/**
* Format: varchar(20)
* @example 1234567890123456789
*/
wantsToBeNotifieRoledId: string | null;
};
};
};
matches?: components["schemas"]["match"][];
matches: components["schemas"]["match"][];
checksum: string;
};
match: {
/**
* Format: varchar(19)
* Format: varcharq(20)
* @example 1234567890123456789
*/
channelID?: string;
channelId: string;
/**
* Format: varchar(50)
* @example Scrim
*/
matchType?: string;
matchType: string;
/**
* Format: varchar(19)
* Format: varchar(20)
* @example 1234567890123456789
*/
createrId?: string;
createrId: string;
/**
* Format: varchar(19)
* Format: varchar(20)
* @example 1234567890123456789
*/
roleId?: string;
roleId: string;
/**
* Format: varchar(100)
* @example ?
*/
opponentName?: string;
opponentName: string;
/**
* Format: varchar(19)
* Format: varchar(20)
* @example 1234567890123456789
*/
messsageId?: string;
/** @example 0 0 1 5 2 2023 60o */
cron?: string;
messageId: string;
/** @example 2020-01-01T00:00:00Z */
utc_ts: string;
};
tp_messages: {
/**
* Format: varchar(20)
* @example 1234567890123456789
*/
channelId: string;
messageIds: {
/**
* Format: varchar(20)
* @example 1234567890123456789
*/
0: string | null;
/**
* Format: varchar(20)
* @example 1234567890123456789
*/
1: string | null;
/**
* Format: varchar(20)
* @example 1234567890123456789
*/
2: string | null;
/**
* Format: varchar(20)
* @example 1234567890123456789
*/
3: string | null;
/**
* Format: varchar(20)
* @example 1234567890123456789
*/
4: string | null;
/**
* Format: varchar(20)
* @example 1234567890123456789
*/
5: string | null;
/**
* Format: varchar(20)
* @example 1234567890123456789
*/
6: string | null;
};
};
};
responses: never;
@ -108,8 +190,34 @@ export type external = Record<string, never>;
export interface operations {
/**
* Find guild config by ID
* @description Returns a single guild config
* Retrieve all guild's configs
* @description Returns all guild's configs.
*/
getGuildsForBoot: {
responses: {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["guildConfig"][];
};
};
/** @description Invalid ID supplied */
400: {
content: never;
};
/** @description Unauthorized */
401: {
content: never;
};
/** @description Guild not found */
404: {
content: never;
};
};
};
/**
* Find a guild's config by ID
* @description Returns a single guild's config.
*/
getGuildById: {
parameters: {
@ -129,6 +237,10 @@ export interface operations {
400: {
content: never;
};
/** @description Unauthorized */
401: {
content: never;
};
/** @description Guild not found */
404: {
content: never;
@ -136,8 +248,8 @@ export interface operations {
};
};
/**
* Deletes a guild config by ID
* @description Delete a guild's config
* Deletes a guild's config by ID
* @description Delete a guild's config when the bot is removed from the guild.
*/
deleteGuildById: {
parameters: {
@ -155,6 +267,10 @@ export interface operations {
400: {
content: never;
};
/** @description Unauthorized */
401: {
content: never;
};
/** @description Guild not found */
404: {
content: never;
@ -162,7 +278,7 @@ export interface operations {
};
};
/**
* Find guild by ID for it's tp_messages
* Find the tp_messages of guild by ID
* @description Returns tp_messages for a guild
*/
getTp_messagesOfGuildById: {
@ -176,7 +292,7 @@ export interface operations {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["guildConfig"];
"application/json": components["schemas"]["tp_messages"];
};
};
/** @description Time planning not enabled for this guild */
@ -187,6 +303,137 @@ export interface operations {
400: {
content: never;
};
/** @description Unauthorized */
401: {
content: never;
};
/** @description Guild not found */
404: {
content: never;
};
};
};
/**
* Put new message IDs for tp_messages of guild by ID
* @description Returns tp_messages for a guild
*/
putTp_messagesOfGuildById: {
parameters: {
path: {
/** @description ID of guild's tp_messages to return */
guildId: string;
};
};
/** @description Put new message IDs for tp_messages in channel */
requestBody: {
content: {
"application/json": components["schemas"]["tp_messages"];
};
};
responses: {
/** @description successful operation */
204: {
content: never;
};
/** @description Invalid ID supplied */
400: {
content: never;
};
/** @description Unauthorized */
401: {
content: never;
};
/** @description Time planning not enabled for this guild */
403: {
content: never;
};
/** @description Guild not found */
404: {
content: never;
};
};
};
/**
* Find all matches of guild by ID
* @description Returns tp_messages for a guild
*/
getMatchesOfGuildById: {
parameters: {
path: {
/** @description ID of guild's tp_messages to return */
guildId: string;
};
};
responses: {
/** @description successful operation */
200: {
content: {
"application/json": {
matches: components["schemas"]["match"][];
/**
* Format: text
* @example Europe/Berlin
*/
timezone: string;
};
};
};
/** @description Time planning not enabled for this guild */
204: {
content: never;
};
/** @description Invalid ID supplied */
400: {
content: never;
};
/** @description Unauthorized */
401: {
content: never;
};
/** @description Guild not found */
404: {
content: never;
};
};
};
/**
* Save a new created match of guild by ID
* @description Returns tp_messages for a guild
*/
postMatchOfGuildById: {
parameters: {
path: {
/** @description ID of match's guild to set */
guildId: string;
};
};
/** @description Save a new created match in channel */
requestBody: {
content: {
"application/json": {
match: components["schemas"]["match"];
/**
* Format: text
* @description Has to match guild tz
* @example Europe/Berlin
*/
timezone: string;
};
};
};
responses: {
/** @description successful operation */
204: {
content: never;
};
/** @description Invalid ID supplied */
400: {
content: never;
};
/** @description Unauthorized */
401: {
content: never;
};
/** @description Guild not found */
404: {
content: never;

25
src/types/lucia-auth.d.ts vendored Normal file
View file

@ -0,0 +1,25 @@
import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core";
import { users } from "~/drizzle/schema";
import { lucia } from "~/lib/auth";
declare module "lucia" {
// eslint-disable-next-line no-unused-vars
interface Register {
Lucia: typeof lucia;
DatabaseUserAttributes: DatabaseUserAttributes;
}
}
type GetColumns<T> =
T extends PgTableWithColumns<infer First> ? First["columns"] : never;
type ExtractDataTypes<T> = {
[K in keyof T]: T[K] extends PgColumn<infer DataType, never, never>
? DataType["data"]
: never;
};
interface DatabaseUserAttributes
extends ExtractDataTypes<GetColumns<typeof users>> {
warst: string;
}