Add guild routes, setup tables, validators, and update environment example
All checks were successful
Code quality checks / biome (push) Successful in 7s
All checks were successful
Code quality checks / biome (push) Successful in 7s
Added routes for guild creation, deletion, joining, leaving, and invites Set up Cassandra tables for guilds, invites, and members Added validators for guild input Updated .env.example with required config values
This commit is contained in:
parent
9d8b3eb969
commit
320e2cc121
14 changed files with 708 additions and 24 deletions
|
@ -1,10 +1,39 @@
|
|||
import { readdir } from "node:fs/promises";
|
||||
import { readdir, stat } from "node:fs/promises";
|
||||
import { extname, join, resolve } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { cassandra as cassandraConfig, verifyRequiredVariables } from "@config";
|
||||
import { logger } from "@creations.works/logger";
|
||||
import { cassandra } from "@lib/cassandra";
|
||||
|
||||
async function loadTables(dir: string): Promise<void> {
|
||||
const entries = await readdir(dir);
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = join(dir, entry);
|
||||
const stats = await stat(fullPath);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
await loadTables(fullPath);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (extname(entry) !== ".ts") continue;
|
||||
|
||||
const modulePath = pathToFileURL(fullPath).href;
|
||||
const mod = await import(modulePath);
|
||||
|
||||
if (typeof mod.default === "function") {
|
||||
await mod.default();
|
||||
logger.info(`Ran default export from ${fullPath}`);
|
||||
} else if (typeof mod.createTable === "function") {
|
||||
await mod.createTable();
|
||||
logger.info(`Ran createTable from ${fullPath}`);
|
||||
} else {
|
||||
logger.warn(`No callable export found in ${fullPath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function setup(): Promise<void> {
|
||||
verifyRequiredVariables();
|
||||
await cassandra.connect({ withKeyspace: false });
|
||||
|
@ -29,24 +58,7 @@ async function setup(): Promise<void> {
|
|||
logger.info(`Keyspace "${keyspace}" ensured and selected.`);
|
||||
|
||||
const tablesDir = resolve("config", "setup", "tables");
|
||||
const files = await readdir(tablesDir);
|
||||
|
||||
for (const file of files) {
|
||||
if (extname(file) !== ".ts") continue;
|
||||
|
||||
const modulePath = pathToFileURL(join(tablesDir, file)).href;
|
||||
const mod = await import(modulePath);
|
||||
|
||||
if (typeof mod.default === "function") {
|
||||
await mod.default();
|
||||
logger.info(`Ran default export from ${file}`);
|
||||
} else if (typeof mod.createTable === "function") {
|
||||
await mod.createTable();
|
||||
logger.info(`Ran createTable from ${file}`);
|
||||
} else {
|
||||
logger.warn(`No callable export found in ${file}`);
|
||||
}
|
||||
}
|
||||
await loadTables(tablesDir);
|
||||
|
||||
logger.info("Setup complete.");
|
||||
}
|
||||
|
@ -58,7 +70,7 @@ setup()
|
|||
})
|
||||
.finally(() => {
|
||||
cassandra.shutdown().catch((error: Error) => {
|
||||
logger.error(["Error shutting down Cassandra client:", error as Error]);
|
||||
logger.error(["Error shutting down Cassandra client:", error]);
|
||||
});
|
||||
|
||||
process.exit(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue