feat: complete last commit

This commit is contained in:
Aron Malcher 2024-01-16 20:24:48 +01:00
parent 55b81fac91
commit c3bf31b3d4
Signed by: aronmal
GPG key ID: 816B7707426FC612
14 changed files with 8344 additions and 58 deletions

View file

@ -1,10 +1,10 @@
import { drizzle } from "drizzle-orm/postgres-js"
import postgres from "postgres"
import * as schema from "./schema"
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";
const queryClient = postgres(process.env.DATABASE_URL ?? "")
const queryClient = postgres(import.meta.env.VITE_DATABASE_URL ?? "");
const db = drizzle(queryClient, {
schema,
})
});
export default db
export default db;

View file

@ -65,14 +65,14 @@ export const verificationTokens = pgTable(
export const matchPlannings = pgTable("match_planning", {
id: serial("id").primaryKey(),
channelId: varchar("channel_id", { length: 19 }).notNull(),
matchtype: varchar("matchtype", { length: 50 }).notNull(),
createrId: varchar("creater_id", { length: 19 }).notNull(),
roleId: varchar("role_id", { length: 19 }).notNull(),
channelId: varchar("channel_id", { length: 20 }).notNull(),
matchtype: varchar("match_type", { length: 50 }).notNull(),
createrId: varchar("creater_id", { length: 20 }).notNull(),
roleId: varchar("role_id", { length: 20 }).notNull(),
opponentName: varchar("opponent_name", { length: 100 }).notNull(),
messageId: varchar("message_id", { length: 19 }).notNull(),
plannedFor: timestamp("planned_for", { precision: 3 }).notNull(),
guildId: varchar("guild_id", { length: 19 })
messageId: varchar("message_id", { length: 20 }).notNull(),
ts: timestamp("ts").notNull(),
guildId: varchar("guild_id", { length: 20 })
.notNull()
.references(() => guilds.id, { onDelete: "cascade" }),
});
@ -85,7 +85,8 @@ export const matchPlanningsRelations = relations(matchPlannings, ({ one }) => ({
}));
export const guilds = pgTable("guild", {
id: varchar("id", { length: 19 }).primaryKey(),
id: varchar("id", { length: 20 }).primaryKey(),
timezone: text("timezone").notNull(),
});
export const guildsRelations = relations(guilds, ({ one, many }) => ({
@ -98,41 +99,42 @@ export const guildsRelations = relations(guilds, ({ one, many }) => ({
export const timePlannings = pgTable("time_planning", {
id: serial("id").primaryKey(),
guildId: varchar("guild_id", { length: 19 })
guildId: varchar("guild_id", { length: 20 })
.notNull()
.unique()
.references(() => guilds.id, {
onDelete: "cascade",
})
.notNull()
.unique(),
channelId: varchar("channel_id", { length: 19 }).notNull(),
targetWeekday: smallint("target_weekday").notNull(),
targetHour: smallint("target_hour").notNull(),
targetMinute: smallint("target_minute").notNull(),
isAvailableRoleId: varchar("is_available_role_id", { length: 19 }),
}),
channelId: varchar("channel_id", { length: 20 }).notNull(),
target_interval: smallint("target_interval").notNull(),
isAvailableRoleId: varchar("is_available_role_id", { length: 20 }),
wantsToBeNotifieRoledId: varchar("wants_to_be_notified_role_id", {
length: 19,
length: 20,
}),
});
export const timePlanningsRelations = relations(
timePlannings,
({ one, many }) => ({
guild: one(tpMessages),
guild: one(guilds, {
fields: [timePlannings.guildId],
references: [guilds.id],
}),
messages: many(tpMessages),
}),
);
export const tpMessages = pgTable("tp_message", {
messageId: varchar("message_id", { length: 19 }).primaryKey(),
messageId: varchar("message_id", { length: 20 }).primaryKey(),
day: smallint("day").notNull(),
planId: varchar("plan_id", { length: 19 })
planId: integer("plan_id")
.notNull()
.references(() => timePlannings.guildId, { onDelete: "cascade" }),
.references(() => timePlannings.id, { onDelete: "cascade" }),
});
export const tpMessagesRelations = relations(tpMessages, ({ one }) => ({
timePlanning: one(timePlannings, {
fields: [tpMessages.messageId],
references: [timePlannings.channelId],
plan: one(timePlannings, {
fields: [tpMessages.planId],
references: [timePlannings.id],
}),
}));

View file

@ -7,15 +7,23 @@ export const authOptions: SolidAuthConfig = {
providers: [
{
...Discord({
clientId: process.env.DISCORD_CLIENT_ID,
clientSecret: process.env.DISCORD_CLIENT_SECRET,
clientId: import.meta.env.VITE_DISCORD_CLIENT_ID,
clientSecret: import.meta.env.VITE_DISCORD_CLIENT_SECRET,
}),
authorization:
"https://discord.com/api/oauth2/authorize?scope=identify+email+guilds+guilds.members.read",
},
],
adapter: DrizzleAdapter(db),
secret: process.env.AUTH_SECRET,
secret: import.meta.env.VITE_AUTH_SECRET,
callbacks: {
session: ({ session, user }) => {
if (session?.user) {
session.user.id = user.id;
}
return session;
},
},
pages: {
// signIn: "/signin",
// signOut: "/signout",
@ -23,4 +31,7 @@ export const authOptions: SolidAuthConfig = {
// verifyRequest: '/auth/verify-request', // (used for check email message)
// newUser: '/auth/new-user' // New users will be directed here on first sign in (leave the property out if not of interest)
},
redirectProxyUrl: import.meta.env.DEV
? import.meta.env.VITE_AUTH_REDIRECT_PROXY_URL
: undefined,
};

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

@ -0,0 +1,15 @@
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
}
}
}

7751
src/types/discord.d.ts vendored Normal file

File diff suppressed because it is too large Load diff

16
src/types/env.d.ts vendored Normal file
View file

@ -0,0 +1,16 @@
/// <reference types="vinxi/client" />
interface ImportMetaEnv {
readonly VITE_DISCORD_CLIENT: string;
readonly VITE_DISCORD_CLIENT_SECRET: string;
readonly VITE_DISCORD_BOT_TOKEN: string;
readonly VITE_AUTH_SECRET: string;
readonly VITE_AUTH_REDIRECT_PROXY_URL: string | undefined;
readonly VITE_DATABASE_URL: string;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}

196
src/types/liljudd.d.ts vendored Normal file
View file

@ -0,0 +1,196 @@
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/
export interface paths {
"/api/config/{guildId}": {
/**
* Find guild config by ID
* @description Returns a single guild config
*/
get: operations["getGuildById"];
/**
* Deletes a guild config by ID
* @description Delete a guild's config
*/
delete: operations["deleteGuildById"];
};
"/api/tp_messages/{guildId}": {
/**
* Find guild by ID for it's tp_messages
* @description Returns tp_messages for a guild
*/
get: operations["getTp_messagesOfGuildById"];
};
}
export type webhooks = Record<string, never>;
export interface components {
schemas: {
guildConfig: {
/**
* Format: varchar(19)
* @example 1234567890123456789
*/
guildID?: string;
features?: {
time_planning?: {
/**
* Format: varchar(19)
* @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;
};
};
matches?: components["schemas"]["match"][];
};
match: {
/**
* Format: varchar(19)
* @example 1234567890123456789
*/
channelID?: string;
/**
* Format: varchar(50)
* @example Scrim
*/
matchType?: string;
/**
* Format: varchar(19)
* @example 1234567890123456789
*/
createrId?: string;
/**
* Format: varchar(19)
* @example 1234567890123456789
*/
roleId?: string;
/**
* Format: varchar(100)
* @example ?
*/
opponentName?: string;
/**
* Format: varchar(19)
* @example 1234567890123456789
*/
messsageId?: string;
/** @example 0 0 1 5 2 2023 60o */
cron?: string;
};
};
responses: never;
parameters: never;
requestBodies: never;
headers: never;
pathItems: never;
}
export type $defs = Record<string, never>;
export type external = Record<string, never>;
export interface operations {
/**
* Find guild config by ID
* @description Returns a single guild config
*/
getGuildById: {
parameters: {
path: {
/** @description ID of guild config to return */
guildId: string;
};
};
responses: {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["guildConfig"];
};
};
/** @description Invalid ID supplied */
400: {
content: never;
};
/** @description Guild not found */
404: {
content: never;
};
};
};
/**
* Deletes a guild config by ID
* @description Delete a guild's config
*/
deleteGuildById: {
parameters: {
path: {
/** @description ID of guild config to delete */
guildId: string;
};
};
responses: {
/** @description successful operation */
204: {
content: never;
};
/** @description Invalid ID supplied */
400: {
content: never;
};
/** @description Guild not found */
404: {
content: never;
};
};
};
/**
* Find guild by ID for it's tp_messages
* @description Returns tp_messages for a guild
*/
getTp_messagesOfGuildById: {
parameters: {
path: {
/** @description ID of guild's tp_messages to return */
guildId: string;
};
};
responses: {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["guildConfig"];
};
};
/** @description Time planning not enabled for this guild */
204: {
content: never;
};
/** @description Invalid ID supplied */
400: {
content: never;
};
/** @description Guild not found */
404: {
content: never;
};
};
};
}