diff --git a/src/db/dbAccess/user.js b/src/db/dbAccess/user.js
index 413b1cf..6301cb5 100644
--- a/src/db/dbAccess/user.js
+++ b/src/db/dbAccess/user.js
@@ -1,23 +1,25 @@
import { hash, compare } from 'bcrypt';
import { DbUser } from '#db/schemas/index.js';
+import { RegisterDto } from '#dto/auth/index.js';
-export async function registerUser(username, password, email, type = 'user') {
- if (!username || !password || !email) {
- throw new Error(
- 'Username, password, and email are required to register a user.'
- );
- }
+/**
+ * @param data {RegisterDto}
+ * @returns {Promise<(Error | HydratedDocument<InferSchemaType<module:mongoose.Schema>, ObtainSchemaGeneric<module:mongoose.Schema, "TVirtuals"> & ObtainSchemaGeneric<module:mongoose.Schema, "TInstanceMethods">, ObtainSchemaGeneric<module:mongoose.Schema, "TQueryHelpers">, ObtainSchemaGeneric<module:mongoose.Schema, "TVirtuals">>)[]>}
+ */
+export async function registerUser(data) {
+ if (!(data instanceof RegisterDto))
+ throw new Error('Invalid data type. Expected RegisterDto.');
- const passwordHash = await hash(password, 10);
+ const passwordHash = await hash(data.password, 10);
if (!passwordHash) {
throw new Error('Failed to hash password.');
}
return DbUser.create({
- username,
+ username: data.username,
passwordHash,
- email,
- type
+ email: data.email,
+ type: data.type
});
}
|