UserService
Source: UserService.js:54
Service for managing user entities and authentication. Handles CRUD operations and user-specific logic.
Constructor
new UserService(): UserServiceInstance Methods
getAll(options): Promise.<Array>
Get all users.
Parameters
options— Options for the query.options.includeDeleted— Whether to include soft-deleted users. Defaults to false.
Returns
Promise.<Array>— Array of user objects.
findDeletedByUsernameOrEmail(
identifiers: string | Array.<string>,
): Promise.<(User|null)>
Find a deleted user by username or email.
Parameters
identifiers(string | Array.<string>) — The username, email, or array of identifiers to search for.
Returns
Promise.<(User|null)>— The deleted user object or null if not found.
findById(id: UUID): Promise.<Object>
Get a user by ID.
Parameters
id(UUID) — The user's ID.
Returns
Promise.<Object>— The user object.
findByUsernameOrEmail(
identifier: string | Array.<string>,
options: Object,
): User
Find a user by username or email.
Parameters
identifier(string | Array.<string>) — The username, email, or array of identifiers to search for.options(Object) — Additional options.options.scope(string | Array.<string>, optional, default: "\"defaultScope\"") — Scope for the query.
Returns
User— The user object.
getCount(): Promise.<number>
Get the total count of users.
Returns
Promise.<number>— The total count of users.
getTrend(): Promise.<number>
Get the trend of user creation and deletion.
Returns
Promise.<number>— The trend value.
create(
username: string,
password: string,
email: string,
emailConfirmed: boolean,
locale: string,
): Promise.<Object>
Create a new user.
Parameters
username(string) — The username of the user.password(string) — The password of the user.email(string) — The email of the user.emailConfirmed(boolean) — Whether the email is confirmed.locale(string) — The locale for notifications.
Returns
Promise.<Object>— The created user object.
findOrCreate(
username: string,
password: string,
): Promise.<Array.<(Object|boolean)>>
Find or create a user.
Parameters
username(string) — The username of the user.password(string) — The password of the user.
Returns
Promise.<Array.<(Object|boolean)>>— The user object and a boolean indicating if the user was created.
generateSocialUsername(provider, displayName)
Generate a username candidate for a social login user.
Parameters
provider— The provider used for social login.displayName— The display name returned by the provider.
Returns
- A sanitized username suitable for creation.
findOrCreateSocialUser(provider, socialId, email, displayName)
Find an existing social user or create a new one from OAuth profile data.
Parameters
provider— The provider used for social login.socialId— The unique provider identifier for the user.email— The email address returned by the provider.displayName— The display name returned by the provider.
Returns
- The existing or newly created user.
update(id: UUID, data: Object): Promise.<Object>
Update a user.
Parameters
id(UUID) — The ID of the user.data(Object) — The data to update.
Returns
Promise.<Object>— The updated user object.
remove(id: UUID): Promise.<void>
Remove a user.
Parameters
id(UUID) — The ID of the user.
Returns
Promise.<void>— Resolves when the user is removed.
restore(id: UUID): Promise.<void>
Restore a soft-deleted user.
Parameters
id(UUID) — The ID of the user.
Returns
Promise.<void>— Resolves when the user is restored.
getLoggedInPercentage(): Promise.<number>
Get the percentage of logged-in users.
Returns
Promise.<number>— The percentage of logged-in users.