UserService
Provides layer to manipulate users.
Constructors
constructor
**new UserService**(«destructured»)
Parameters
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CREATED
stringRequiredDefault: "user.created"
Events.DELETED
stringRequiredDefault: "user.deleted"
Events.PASSWORD_RESET
stringRequiredDefault: "user.password_reset"
Events.UPDATED
stringRequiredDefault: "user.updated"
Accessors
activeManager_
Protected get**activeManager_**(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredMethods
atomicPhase_
Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>
Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
Promise
Promise<TResult>Requiredcreate
**create**(user, password): Promise<[User](/references/services/classes/User)>
Creates a user with username being validated. Fails if email is not a valid format.
Parameters
password
stringRequiredReturns
Promise<User>
delete
**delete**(userId): Promise<void>
Deletes a user from a given user id.
Parameters
userId
stringRequiredReturns
Promise<void>
Promise
Promise<void>RequiredgenerateResetPasswordToken
**generateResetPasswordToken**(userId): Promise<string>
Generate a JSON Web token, that will be sent to a user, that wishes to reset password. The token will be signed with the users current password hash as a secret a long side a payload with userId and the expiry time for the token, which is always 15 minutes.
Parameters
userId
stringRequiredReturns
Promise<string>
Promise
Promise<string>RequiredhashPassword_
**hashPassword_**(password): Promise<string>
Hashes a password
Parameters
password
stringRequiredReturns
Promise<string>
Promise
Promise<string>Requiredlist
**list**(selector, config?): Promise<[User](/references/services/classes/User)[]>
Parameters
config
objectRequiredDefault: {}
Returns
Promise<User[]>
retrieve
**retrieve**(userId, config?): Promise<[User](/references/services/classes/User)>
Gets a user by id. Throws in case of DB Error and if user was not found.
Parameters
userId
stringRequiredDefault: {}
Returns
Promise<User>
retrieveByApiToken
**retrieveByApiToken**(apiToken, relations?): Promise<[User](/references/services/classes/User)>
Gets a user by api token. Throws in case of DB Error and if user was not found.
Parameters
apiToken
stringRequiredrelations
string[]RequiredDefault: []
Returns
Promise<User>
retrieveByEmail
**retrieveByEmail**(email, config?): Promise<[User](/references/services/classes/User)>
Gets a user by email. Throws in case of DB Error and if user was not found.
Parameters
email
stringRequiredDefault: {}
Returns
Promise<User>
setPassword_
**setPassword_**(userId, password): Promise<[User](/references/services/classes/User)>
Sets a password for a user Fails if no user exists with userId and if the hashing of the new password does not work.
Parameters
userId
stringRequiredpassword
stringRequiredReturns
Promise<User>
shouldRetryTransaction_
Protected **shouldRetryTransaction_**(err): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanupdate
**update**(userId, update): Promise<[User](/references/services/classes/User)>
Updates a user.
Parameters
userId
stringRequiredReturns
Promise<User>
withTransaction
**withTransaction**(transactionManager?): [UserService](/references/services/classes/UserService)
Parameters
transactionManager
EntityManager