Fix: Finished Backend

This commit is contained in:
aronmal 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

View file

@ -1,8 +1,8 @@
import { relations } from "drizzle-orm";
import {
boolean,
integer,
pgTable,
primaryKey,
serial,
smallint,
text,
@ -37,10 +37,51 @@ export const discordTokens = pgTable("tokens", {
expiresAt: timestamp("expires_at", { mode: "date" }).notNull(),
});
export const matchPlannings = pgTable("match_planning", {
export const guilds = pgTable("guilds", {
id: varchar("id", { length: 20 }).primaryKey(),
timezone: text("timezone").notNull().default("Etc/UTC"),
tpEnabled: boolean("tp_enabled").notNull().default(false),
tpChannelId: varchar("tp_channel_id", { length: 20 }),
tpInterval: smallint("target_interval").notNull(),
tpRoles: boolean("tp_roles").notNull(),
isAvailableRoleId: varchar("is_available_role_id", { length: 20 }),
wantsToBeNotifieRoledId: varchar("wants_to_be_notified_role_id", {
length: 20,
}),
});
export const guildsRelations = relations(guilds, ({ many }) => ({
tpMessages: many(tpMessages),
matches: many(matches),
}));
export const tpMessages = pgTable(
"tp_messages",
{
messageId: varchar("message_id", { length: 20 }),
day: smallint("day").notNull(),
guildId: varchar("guild_id", { length: 20 })
.notNull()
.references(() => guilds.id, { onDelete: "cascade" }),
},
(table) => {
return {
pk: primaryKey({ columns: [table.guildId, table.day] }),
};
},
);
export const tpMessagesRelations = relations(tpMessages, ({ one }) => ({
guild: one(guilds, {
fields: [tpMessages.guildId],
references: [guilds.id],
}),
}));
export const matches = pgTable("matches", {
id: serial("id").primaryKey(),
channelId: varchar("channel_id", { length: 20 }).notNull(),
matchtype: varchar("match_type", { length: 50 }).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(),
@ -51,65 +92,9 @@ export const matchPlannings = pgTable("match_planning", {
.references(() => guilds.id, { onDelete: "cascade" }),
});
export const matchPlanningsRelations = relations(matchPlannings, ({ one }) => ({
export const matchPlanningsRelations = relations(matches, ({ one }) => ({
guild: one(guilds, {
fields: [matchPlannings.guildId],
fields: [matches.guildId],
references: [guilds.id],
}),
}));
export const guilds = pgTable("guild", {
id: varchar("id", { length: 20 }).primaryKey(),
timezone: text("timezone").notNull(),
});
export const guildsRelations = relations(guilds, ({ one, many }) => ({
matches: many(matchPlannings),
timePlanning: one(timePlannings, {
fields: [guilds.id],
references: [timePlannings.guildId],
}),
}));
export const timePlannings = pgTable("time_planning", {
id: serial("id").primaryKey(),
guildId: varchar("guild_id", { length: 20 })
.notNull()
.unique()
.references(() => guilds.id, {
onDelete: "cascade",
}),
channelId: varchar("channel_id", { length: 20 }).notNull(),
target_interval: smallint("target_interval").notNull(),
roles: boolean("roles").notNull(),
isAvailableRoleId: varchar("is_available_role_id", { length: 20 }),
wantsToBeNotifieRoledId: varchar("wants_to_be_notified_role_id", {
length: 20,
}),
});
export const timePlanningsRelations = relations(
timePlannings,
({ one, many }) => ({
guild: one(guilds, {
fields: [timePlannings.guildId],
references: [guilds.id],
}),
messages: many(tpMessages),
}),
);
export const tpMessages = pgTable("tp_message", {
messageId: varchar("message_id", { length: 20 }).primaryKey(),
day: smallint("day").notNull(),
planId: integer("plan_id")
.notNull()
.references(() => timePlannings.id, { onDelete: "cascade" }),
});
export const tpMessagesRelations = relations(tpMessages, ({ one }) => ({
plan: one(timePlannings, {
fields: [tpMessages.planId],
references: [timePlannings.id],
}),
}));