mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
code: user,get,dbal (1 files)
This commit is contained in:
@@ -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<Result<User>> {
|
||||
if (!id) {
|
||||
return { success: false, error: { code: 'VALIDATION_ERROR', message: 'ID required' } };
|
||||
export const getUser = async (store: InMemoryStore, id: string): Promise<Result<User>> => {
|
||||
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<Result<User>> {
|
||||
export const getUserByEmail = async (store: InMemoryStore, email: string): Promise<Result<User>> => {
|
||||
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<Result<User>> {
|
||||
export const getUserByUsername = async (store: InMemoryStore, username: string): Promise<Result<User>> => {
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user