From 9d33b2fe6b3fbea60d981d9f4ed24cf82b05a7af Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 29 May 2025 22:48:16 +0200 Subject: Prettier config --- src/db/db.js | 30 +++++++++++++++--------------- src/db/index.js | 4 ++-- src/db/schemas/user.js | 32 +++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 26 deletions(-) (limited to 'src/db') diff --git a/src/db/db.js b/src/db/db.js index 36f2105..9a7b50e 100644 --- a/src/db/db.js +++ b/src/db/db.js @@ -1,19 +1,19 @@ -import { connect } from "mongoose"; -import { readSecret } from "#util/secretUtils.js"; +import { connect } from 'mongoose'; +import { readSecret } from '#util/secretUtils.js'; export async function initDb() { - const connectionString = await readSecret( - process.env["DATABASE_SECRET_PATH"], - ); - try { - const res = await connect(connectionString); - if (res.connection.readyState === 1) { - console.log("[MONGODB] Connected successfully!"); - } else { - console.error("[MONGODB] Failed to connect to ", connectionString); + const connectionString = await readSecret( + process.env['DATABASE_SECRET_PATH'] + ); + try { + const res = await connect(connectionString); + if (res.connection.readyState === 1) { + console.log('[MONGODB] Connected successfully!'); + } else { + console.error('[MONGODB] Failed to connect to ', connectionString); + } + } catch (e) { + console.error('[MONGODB] Error connecting to database!'); + throw e; } - } catch (e) { - console.error("[MONGODB] Error connecting to database!"); - throw e; - } } diff --git a/src/db/index.js b/src/db/index.js index f55b773..cd306b7 100644 --- a/src/db/index.js +++ b/src/db/index.js @@ -1,2 +1,2 @@ -export * from "./db.js"; -export * from "./schemas/index.js"; +export * from './db.js'; +export * from './schemas/index.js'; diff --git a/src/db/schemas/user.js b/src/db/schemas/user.js index eaddb08..da2516c 100644 --- a/src/db/schemas/user.js +++ b/src/db/schemas/user.js @@ -1,14 +1,28 @@ -import { model, Schema } from "mongoose"; +import { model, Schema } from 'mongoose'; export const userSchema = new Schema({ - username: { - type: String, - required: true, - unique: true, - trim: true, - }, + username: { + type: String, + required: true, + unique: true, + trim: true + }, + passwordHash: { + type: String, + required: true + }, + email: { + type: String, + required: true, + unique: true, + trim: true + }, + createdAt: { + type: Date, + default: Date.now + } }); -export const User = model("user", userSchema); +export const User = model('user', userSchema); -console.log("[MONGODB] User schema initialized successfully!"); +console.log('[MONGODB] User schema initialized successfully!'); -- cgit 1.5.1