summary refs log tree commit diff
path: root/src/db
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-06-03 01:01:40 +0200
committerRory& <root@rory.gay>2025-06-03 01:01:40 +0200
commit6f3f08ed340e59a62a2d0428a5c32f99551ef1ce (patch)
treeff77390b1d3ea61414c14c94ac1fa2a05030879b /src/db
parentMore alarm testing (diff)
downloadnodejs-final-assignment-6f3f08ed340e59a62a2d0428a5c32f99551ef1ce.tar.xz
Fix performance issues, add fake user bot to test client, more testing
Diffstat (limited to 'src/db')
-rw-r--r--src/db/db.js2
-rw-r--r--src/db/dbAccess/user.js6
-rw-r--r--src/db/schemas/user.js23
3 files changed, 16 insertions, 15 deletions
diff --git a/src/db/db.js b/src/db/db.js

index 2035731..9cbba80 100644 --- a/src/db/db.js +++ b/src/db/db.js
@@ -7,7 +7,7 @@ export async function initDb() { process.env['DATABASE_SECRET_PATH'] ); - if (process.env['LOG_QUERIES']) mongoose.set('debug', true); + if (process.env['LOG_QUERIES'] === 'true') mongoose.set('debug', true); try { const res = await connect(connectionString); diff --git a/src/db/dbAccess/user.js b/src/db/dbAccess/user.js
index 3bb06b6..69a83e4 100644 --- a/src/db/dbAccess/user.js +++ b/src/db/dbAccess/user.js
@@ -16,7 +16,6 @@ export async function getUserById(id) { }); } - console.log(user); return user; } @@ -32,7 +31,6 @@ async function getUserByAuth(data) { user = await DbUser.findOne({ username: data.username }); } - console.log('user', user); if (!user) { // Sneaky: prevent user enumeration throw new SafeNSoundError({ @@ -60,7 +58,7 @@ export async function registerUser(data) { if (!(data instanceof RegisterDto)) throw new Error('Invalid data type. Expected RegisterDto.'); - const salt = await genSalt(12); + const salt = await genSalt(1); const passwordHash = await hash(data.password, salt); if (!passwordHash) { throw new Error('Failed to hash password.'); @@ -88,7 +86,7 @@ export async function deleteUser(data) { export async function loginUser(data, deviceName) { const user = await getUserByAuth(data); const device = await user.devices.create({ - name: deviceName + name: deviceName ?? 'Unknown Device' }); user.devices.push(device); diff --git a/src/db/schemas/user.js b/src/db/schemas/user.js
index 7680319..7a4b2f4 100644 --- a/src/db/schemas/user.js +++ b/src/db/schemas/user.js
@@ -30,18 +30,21 @@ export const deviceSchema = new Schema({ } }); -export const alarmSchema = new Schema({ - createdAt: { - type: Date, - default: Date.now, - immutable: true +export const alarmSchema = new Schema( + { + reason: { + type: String, + enum: Object.values(AlarmType), + required: true + } }, - reason: { - type: String, - enum: Object.values(AlarmType), - required: true + { + timestamps: { + createdAt: true, + updatedAt: false + } } -}); +); /** * User schema for MongoDB.