UserService
Provides layer to manipulate users.
Properties
__configModule__Record<string, unknown>__container__anyRequired__moduleDeclaration__Record<string, unknown>manager_EntityManagerRequiredtransactionManager_undefined | EntityManagerRequiredEventsobjectRequiredEvents.CREATEDstringRequiredEvents.DELETEDstringRequiredEvents.PASSWORD_RESETstringRequiredEvents.UPDATEDstringRequiredAccessors
activeManager_
Protected get activeManager_(): EntityManager
Returns
EntityManager
EntityManagerEntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
atomicPhase_
Protected atomicPhase_<TResult, 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.
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
PromisePromise<TResult>RequiredInherited from
TransactionBaseService.atomicPhase_
create
create(user, password): Promise<User>
Creates a user with username being validated. Fails if email is not a valid format.
Parameters
passwordstringRequiredReturns
Promise<User>
the result of create
delete
delete(userId): Promise<void>
Deletes a user from a given user id.
Parameters
userIdstringRequiredReturns
Promise<void>
PromisePromise<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
userIdstringRequiredReturns
Promise<string>
PromisePromise<string>Requiredthe generated JSON web token
PromisePromise<string>RequiredhashPassword_
hashPassword_(password): Promise<string>
Hashes a password
Parameters
passwordstringRequiredReturns
Promise<string>
PromisePromise<string>Requiredhashed password
PromisePromise<string>Requiredlist
list(selector, config?): Promise<User[]>
Parameters
configobjectReturns
Promise<User[]>
the result of the find operation
retrieve
retrieve(userId, config?): Promise<User>
Gets a user by id. Throws in case of DB Error and if user was not found.
Parameters
userIdstringRequiredconfigFindConfig<User>Returns
Promise<User>
the user document.
retrieveByApiToken
retrieveByApiToken(apiToken, relations?): Promise<User>
Gets a user by api token. Throws in case of DB Error and if user was not found.
Parameters
apiTokenstringRequiredrelationsstring[]Returns
Promise<User>
the user document.
retrieveByEmail
retrieveByEmail(email, config?): Promise<User>
Gets a user by email. Throws in case of DB Error and if user was not found.
Parameters
emailstringRequiredconfigFindConfig<User>Returns
Promise<User>
the user document.
setPassword_
setPassword_(userId, password): Promise<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
userIdstringRequiredpasswordstringRequiredReturns
Promise<User>
the result of the update operation
shouldRetryTransaction_
Protected shouldRetryTransaction_(err): boolean
Parameters
errRecord<string, unknown> | { code: string }RequiredReturns
boolean
booleanbooleanInherited from
TransactionBaseService.shouldRetryTransaction_
update
update(userId, update): Promise<User>
Updates a user.
Parameters
userIdstringRequiredReturns
Promise<User>
the result of create
withTransaction
withTransaction(transactionManager?): UserService
Parameters
transactionManagerEntityManager