Skip to content

BeechCMS


BeechCMS / @beechcms/core / IUserRepository

Interface: IUserRepository ​

Methods ​

changePasswordAndRevokeSessions() ​

changePasswordAndRevokeSessions(userId, newPasswordHash, nowTimestamp): Promise<void>

Replaces the password hash and revokes every active refresh token of the user in one atomic write, so a password change can never leave old sessions valid.

Parameters ​

userId ​

string

newPasswordHash ​

string

nowTimestamp ​

number

Returns ​

Promise<void>


countAll() ​

countAll(): Promise<number>

Returns the total number of registered users. Used to block re-setup when at least one administrator account already exists.

Returns ​

Promise<number>


create() ​

create(user): Promise<void>

Inserts a new user record.

Parameters ​

user ​

NewUserInput

Returns ​

Promise<void>


createInitialAdmin() ​

createInitialAdmin(user, roleGrant): Promise<boolean>

Atomically creates the first administrator account AND its roleGrant, guarded by a setup-completed marker row inserted in the same transaction. The account can never exist without its role: callers must resolve the grant before calling this, so a missing or unresolvable role aborts setup with nothing written instead of leaving a stranded, unrecoverable admin. Returns false instead of throwing when setup was already completed concurrently.

Parameters ​

user ​

NewUserInput

roleGrant ​

InitialRoleGrant

Returns ​

Promise<boolean>


emailBelongsToAnotherUser() ​

emailBelongsToAnotherUser(email, currentUserId): Promise<boolean>

Checks whether the given email is already registered to a different user. Used during an email change to detect conflicts without exposing whether an unrelated account exists.

Parameters ​

email ​

string

currentUserId ​

string

Returns ​

Promise<boolean>


findAccountById() ​

findAccountById(userId): Promise<AccountSummary | null>

One account by id, without credential material. Null when absent.

Parameters ​

userId ​

string

Returns ​

Promise<AccountSummary | null>


findByEmail() ​

findByEmail(email): Promise<UserRecord | null>

Retrieves a user by their email address, or null if not found.

Parameters ​

email ​

string

Returns ​

Promise<UserRecord | null>


findById() ​

findById(userId): Promise<UserRecord | null>

Retrieves a user by their unique identifier, or null if not found.

Parameters ​

userId ​

string

Returns ​

Promise<UserRecord | null>


findUiPreferences() ​

findUiPreferences(userId): Promise<string | null>

The user's stored UI preferences container (users.ui_prefs) as a raw JSON string, or null when the user does not exist. Parsing and defaults belong to parseStoredUiPreferences.

Parameters ​

userId ​

string

Returns ​

Promise<string | null>


listAccounts() ​

listAccounts(page): Promise<AccountSummary[]>

One page of accounts, oldest first, without credential material.

Parameters ​

page ​

PageRequest

Returns ​

Promise<AccountSummary[]>


setActive() ​

setActive(userId, isActive): Promise<AdminGuardedResult>

Flips users.is_active. not-found when the user does not exist. Reversible by design (brief §4): rows, assignments and tokens are all preserved. Deactivation returns last-global-admin and changes nothing when the account is the last active global administrator.

Parameters ​

userId ​

string

isActive ​

boolean

Returns ​

Promise<AdminGuardedResult>


updateAvatarUrl() ​

updateAvatarUrl(userId, avatarUrl): Promise<void>

Sets or clears the user's avatar URL.

Parameters ​

userId ​

string

avatarUrl ​

string | null

Returns ​

Promise<void>


updateNotificationPreferences() ​

updateNotificationPreferences(userId, preferencesJson): Promise<void>

Persists the user's notification preferences as a JSON string.

Parameters ​

userId ​

string

preferencesJson ​

string

Returns ​

Promise<void>


updatePasswordHash() ​

updatePasswordHash(userId, newPasswordHash): Promise<void>

Replaces the user's stored password hash after a successful password change.

Parameters ​

userId ​

string

newPasswordHash ​

string

Returns ​

Promise<void>


updateProfile() ​

updateProfile(userId, fields): Promise<void>

Updates the user's display name, surname, and/or email address.

Parameters ​

userId ​

string

fields ​
email? ​

string

name? ​

string

surname? ​

string

Returns ​

Promise<void>


updateUiPreferences() ​

updateUiPreferences(userId, preferencesJson): Promise<boolean>

Replaces the user's UI preferences container with preferencesJson, already validated against uiPreferencesSchema. Returns false when no user row matched, so nothing was written.

Parameters ​

userId ​

string

preferencesJson ​

string

Returns ​

Promise<boolean>