leistungsbilanz-ts/src/domain/ports/user.store.ts

40 lines
1 KiB
TypeScript

import type { UserRole } from "../../shared/constants/user-roles.js";
export interface UserAccount {
id: string;
username: string;
passwordHash: string;
name: string;
role: UserRole;
active: boolean;
mustChangePassword: boolean;
createdAt: Date;
updatedAt: Date;
}
export interface CreateUserAccount {
username: string;
name: string;
role: UserRole;
passwordHash: string;
}
export class UsernameAlreadyExistsStoreError extends Error {}
export class LastActiveAdminStoreError extends Error {}
export interface UserStore {
list(): Promise<UserAccount[]>;
count(): Promise<number>;
findById(userId: string): Promise<UserAccount | null>;
findByUsername(username: string): Promise<UserAccount | null>;
create(input: CreateUserAccount): Promise<UserAccount | null>;
updateRoleAndActive(
userId: string,
patch: { role?: UserRole; active?: boolean }
): Promise<UserAccount | null>;
setPassword(
userId: string,
passwordHash: string,
mustChangePassword: boolean
): Promise<UserAccount | null>;
}