All files / src/features/account account.server.ts

100% Statements 5/5
100% Branches 2/2
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32                                                3x 1x   2x 2x 2x    
// The account page's changes (openspec: account). The name is changed through
// authentication's setDisplayName; the language here.
import type { UserRepository } from '#/features/authentication/user.repository.server'
import type { Locale } from '#/paraglide/runtime.js'
import type { Logger } from '#/server/log/log'
 
export interface AccountDeps {
  /** The signed-in user. */
  userId: string
  /** Their stored language. */
  currentLocale: Locale
  users: UserRepository
  log: Logger
  now: () => Date
}
 
/**
 * Stores the language on the account (spec: "Choosing the language on the
 * account page"). The current language changes nothing.
 */
export async function setLanguage(
  deps: AccountDeps,
  locale: Locale,
): Promise<{ ok: true; changed: boolean }> {
  if (locale === deps.currentLocale) {
    return { ok: true, changed: false }
  }
  await deps.users.setLocale(deps.userId, locale, deps.now())
  deps.log.info('authentication.locale_changed', { locale, source: 'account' })
  return { ok: true, changed: true }
}