Skip to main content
Skip to main content

UserService

Provides layer to manipulate users.

constructor

Parameters

__namedParametersUserServicePropsRequired

Properties

manager_EntityManagerRequired
transactionManager_undefined | EntityManagerRequired
__container__anyRequired
EventsobjectRequired
Events.PASSWORD_RESETstringRequired

Default: "user.password_reset"

Events.CREATEDstringRequired

Default: "user.created"

Events.UPDATEDstringRequired

Default: "user.updated"

Events.DELETEDstringRequired

Default: "user.deleted"

analyticsConfigService_AnalyticsConfigServiceRequired
userRepository_Repository<User>Required
eventBus_EventBusServiceRequired
featureFlagRouter_FlagRouterRequired
__configModule__Record<string, unknown>
__moduleDeclaration__Record<string, unknown>

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

Methods

withTransaction

Parameters

transactionManagerEntityManager

Returns

thisthisRequired

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

Returns

booleanbooleanRequired

atomicPhase_

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.

Type Parameters

TResultobjectRequired
TErrorobjectRequired

Parameters

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns

PromisePromise<TResult>Required
the result of the transactional work

list

Parameters

selectorSelector<FilterableUserProps> & objectRequired
the query object for find

Default: {}

configFindConfig<FilterableUserProps>Required
the configuration object for the query

Returns

PromisePromise<User[]>Required
the result of the find operation

listAndCount

Parameters

selectorSelector<FilterableUserProps> & objectRequired

Default: {}

configFindConfig<FilterableUserProps>Required

Returns

PromisePromise<[User[], number]>Required

retrieve

Gets a user by id. Throws in case of DB Error and if user was not found.

Parameters

userIdstringRequired
the id of the user to get.
configFindConfig<User>Required
query configs

Default: {}

Returns

PromisePromise<User>Required
the user document.

retrieveByApiToken

Gets a user by api token. Throws in case of DB Error and if user was not found.

Parameters

apiTokenstringRequired
the token of the user to get.
relationsstring[]Required
relations to include with the user.

Default: []

Returns

PromisePromise<User>Required
the user document.

retrieveByEmail

Gets a user by email. Throws in case of DB Error and if user was not found.

Parameters

emailstringRequired
the email of the user to get.
configFindConfig<User>Required
query config

Default: {}

Returns

PromisePromise<User>Required
the user document.

hashPassword_

Hashes a password

Parameters

passwordstringRequired
the value to hash

Returns

PromisePromise<string>Required
hashed password

create

Creates a user with username being validated. Fails if email is not a valid format.

Parameters

userCreateUserInputRequired
the user to create
passwordstringRequired
user's password to hash

Returns

PromisePromise<User>Required
the result of create

update

Updates a user.

Parameters

userIdstringRequired
id of the user to update
updateUpdateUserInputRequired
the values to be updated on the user

Returns

PromisePromise<User>Required
the result of create

delete

Deletes a user from a given user id.

Parameters

userIdstringRequired
the id of the user to delete. Must be castable as an ObjectId

Returns

PromisePromise<void>Required
the result of the delete operation.

setPassword_

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

userIdstringRequired
the userId to set password for
passwordstringRequired
the old password to set

Returns

PromisePromise<User>Required
the result of the update operation

generateResetPasswordToken

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

userIdstringRequired
the id of the user to reset password for

Returns

PromisePromise<string>Required
the generated JSON web token
Was this section helpful?