mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
fix(users): Using the users entity in the use cases
This commit is contained in:
+4
-11
@@ -3,7 +3,7 @@
|
|||||||
functions are called by the /user REST API endpoints.
|
functions are called by the /user REST API endpoints.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// const UserModel = require('../adapters/localdb/models/users')
|
const UserEntity = require('../entities/user')
|
||||||
const { wlogger } = require('../adapters/wlogger')
|
const { wlogger } = require('../adapters/wlogger')
|
||||||
|
|
||||||
class UserLib {
|
class UserLib {
|
||||||
@@ -17,6 +17,7 @@ class UserLib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Encapsulate dependencies
|
// Encapsulate dependencies
|
||||||
|
this.UserEntity = new UserEntity()
|
||||||
this.UserModel = this.adapters.localdb.Users
|
this.UserModel = this.adapters.localdb.Users
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,17 +25,9 @@ class UserLib {
|
|||||||
async createUser (userObj) {
|
async createUser (userObj) {
|
||||||
try {
|
try {
|
||||||
// Input Validation
|
// Input Validation
|
||||||
if (!userObj.email || typeof userObj.email !== 'string') {
|
|
||||||
throw new Error("Property 'email' must be a string!")
|
|
||||||
}
|
|
||||||
if (!userObj.password || typeof userObj.password !== 'string') {
|
|
||||||
throw new Error("Property 'password' must be a string!")
|
|
||||||
}
|
|
||||||
if (!userObj.name || typeof userObj.name !== 'string') {
|
|
||||||
throw new Error("Property 'name' must be a string!")
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = new this.UserModel(userObj)
|
const userEntity = this.UserEntity.validate(userObj)
|
||||||
|
const user = new this.UserModel(userEntity)
|
||||||
|
|
||||||
// Enforce default value of 'user'
|
// Enforce default value of 'user'
|
||||||
user.type = 'user'
|
user.type = 'user'
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ describe('#users-use-case', () => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// console.log(err)
|
// console.log(err)
|
||||||
// assert.equal(err.status, 422)
|
// assert.equal(err.status, 422)
|
||||||
assert.include(err.message, 'Cannot read property')
|
assert.include(err.message, "Property 'email' must be a string!")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user