diff --git a/dbal/ts/src/core/entities/user/get-user.ts b/dbal/ts/src/core/entities/user/get-user.ts index 5cca9c60b..d23ffa603 100644 --- a/dbal/ts/src/core/entities/user/get-user.ts +++ b/dbal/ts/src/core/entities/user/get-user.ts @@ -2,53 +2,55 @@ * @file get-user.ts * @description Get user operations */ -import type { User, Result } from '../types'; -import type { InMemoryStore } from '../store/in-memory-store'; +import type { Result, User } from '../../types' +import type { InMemoryStore } from '../../store/in-memory-store' +import { validateId } from '../../validation/validate-id' /** * Get a user by ID */ -export async function getUser(store: InMemoryStore, id: string): Promise> { - if (!id) { - return { success: false, error: { code: 'VALIDATION_ERROR', message: 'ID required' } }; +export const getUser = async (store: InMemoryStore, id: string): Promise> => { + const idErrors = validateId(id) + if (idErrors.length > 0) { + return { success: false, error: { code: 'VALIDATION_ERROR', message: idErrors[0] } } } - const user = store.users.get(id); + const user = store.users.get(id) if (!user) { - return { success: false, error: { code: 'NOT_FOUND', message: `User not found: ${id}` } }; + return { success: false, error: { code: 'NOT_FOUND', message: `User not found: ${id}` } } } - return { success: true, data: user }; + return { success: true, data: user } } /** * Get a user by email */ -export async function getUserByEmail(store: InMemoryStore, email: string): Promise> { +export const getUserByEmail = async (store: InMemoryStore, email: string): Promise> => { if (!email) { - return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Email required' } }; + return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Email is required' } } } - const id = store.userEmails.get(email); + const id = store.usersByEmail.get(email) if (!id) { - return { success: false, error: { code: 'NOT_FOUND', message: `User not found: ${email}` } }; + return { success: false, error: { code: 'NOT_FOUND', message: `User not found: ${email}` } } } - return getUser(store, id); + return getUser(store, id) } /** * Get a user by username */ -export async function getUserByUsername(store: InMemoryStore, username: string): Promise> { +export const getUserByUsername = async (store: InMemoryStore, username: string): Promise> => { if (!username) { - return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Username required' } }; + return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Username is required' } } } - const id = store.userUsernames.get(username); + const id = store.usersByUsername.get(username) if (!id) { - return { success: false, error: { code: 'NOT_FOUND', message: `User not found: ${username}` } }; + return { success: false, error: { code: 'NOT_FOUND', message: `User not found: ${username}` } } } - return getUser(store, id); + return getUser(store, id) }