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.
|