From 8ff1c37223c3fa5fdc1076e16df9065697c09ab5 Mon Sep 17 00:00:00 2001 From: rUv Date: Wed, 6 Aug 2025 13:59:59 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20Checkpoint:=20Edit=20/workspaces?= =?UTF-8?q?/claude-code-flow/user-service/src/repositories/user.repository?= =?UTF-8?q?.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchmark/.claude/checkpoints/1754488787.json | 1 + benchmark/.claude/checkpoints/1754488788.json | 1 + .../src/repositories/user.repository.ts | 178 ++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 benchmark/.claude/checkpoints/1754488787.json create mode 100644 benchmark/.claude/checkpoints/1754488788.json create mode 100644 user-service/src/repositories/user.repository.ts diff --git a/benchmark/.claude/checkpoints/1754488787.json b/benchmark/.claude/checkpoints/1754488787.json new file mode 100644 index 0000000000..9d37d12a6e --- /dev/null +++ b/benchmark/.claude/checkpoints/1754488787.json @@ -0,0 +1 @@ +{"branch": "checkpoint/pre-edit-20250806-135946", "file": "/workspaces/claude-code-flow/benchmark/src/swarm_benchmark/cli/main.py", "timestamp": "2025-08-06T13:59:47Z", "type": "pre-edit", "original_branch": "alpha-88"} diff --git a/benchmark/.claude/checkpoints/1754488788.json b/benchmark/.claude/checkpoints/1754488788.json new file mode 100644 index 0000000000..ca6d195041 --- /dev/null +++ b/benchmark/.claude/checkpoints/1754488788.json @@ -0,0 +1 @@ +{"tag": "checkpoint-20250806-135948", "file": "/workspaces/claude-code-flow/benchmark/src/swarm_benchmark/cli/main.py", "timestamp": "2025-08-06T13:59:48Z", "type": "post-edit", "branch": "alpha-88", "diff_summary": " .claude-flow/metrics/performance.json | 2 +- .claude-flow/metrics/system-metrics.json | 24 +++++++++++ .claude-flow/metrics/task-metrics.json | 6 +-- .claude/checkpoints/1754488763.json | 1 + .claude/checkpoints/1754488765.json | 1 + benchmark/.claude-flow/metrics/performance.json | 2 +- benchmark/.claude-flow/metrics/task-metrics.json | 6 +-- benchmark/src/swarm_benchmark/cli/main.py | 53 +++++++++++++++++++++++- claude-flow-wiki | 0 9 files changed, 85 insertions(+), 10 deletions(-) "} diff --git a/user-service/src/repositories/user.repository.ts b/user-service/src/repositories/user.repository.ts new file mode 100644 index 0000000000..70139326b6 --- /dev/null +++ b/user-service/src/repositories/user.repository.ts @@ -0,0 +1,178 @@ +import { v4 as uuidv4 } from 'uuid'; +import { + User, + CreateUserDTO, + UpdateUserDTO, + UserRole, + UserStatus, + PaginationOptions, + PaginatedResult, + UserFilter +} from '../types/user.types'; + +// In-memory storage for demonstration +// In production, replace with actual database implementation +class UserRepository { + private users: Map = new Map(); + + async create(data: CreateUserDTO): Promise { + const user: User = { + id: uuidv4(), + ...data, + role: data.role || UserRole.USER, + status: UserStatus.ACTIVE, + emailVerified: false, + createdAt: new Date(), + updatedAt: new Date(), + }; + + this.users.set(user.id, user); + return { ...user }; + } + + async findById(id: string): Promise { + const user = this.users.get(id); + return user ? { ...user } : null; + } + + async findByEmail(email: string): Promise { + for (const user of this.users.values()) { + if (user.email.toLowerCase() === email.toLowerCase()) { + return { ...user }; + } + } + return null; + } + + async findByUsername(username: string): Promise { + for (const user of this.users.values()) { + if (user.username.toLowerCase() === username.toLowerCase()) { + return { ...user }; + } + } + return null; + } + + async update(id: string, data: UpdateUserDTO): Promise { + const user = this.users.get(id); + if (!user) return null; + + const updatedUser = { + ...user, + ...data, + updatedAt: new Date(), + }; + + this.users.set(id, updatedUser); + return { ...updatedUser }; + } + + async delete(id: string): Promise { + return this.users.delete(id); + } + + async softDelete(id: string): Promise { + const user = this.users.get(id); + if (!user) return null; + + const updatedUser = { + ...user, + status: UserStatus.DELETED, + updatedAt: new Date(), + }; + + this.users.set(id, updatedUser); + return { ...updatedUser }; + } + + async findAll( + filter: UserFilter = {}, + pagination: PaginationOptions + ): Promise> { + let filteredUsers = Array.from(this.users.values()); + + // Apply filters + if (filter.role) { + filteredUsers = filteredUsers.filter(u => u.role === filter.role); + } + if (filter.status) { + filteredUsers = filteredUsers.filter(u => u.status === filter.status); + } + if (filter.emailVerified !== undefined) { + filteredUsers = filteredUsers.filter(u => u.emailVerified === filter.emailVerified); + } + if (filter.search) { + const searchLower = filter.search.toLowerCase(); + filteredUsers = filteredUsers.filter(u => + u.email.toLowerCase().includes(searchLower) || + u.username.toLowerCase().includes(searchLower) || + u.firstName?.toLowerCase().includes(searchLower) || + u.lastName?.toLowerCase().includes(searchLower) + ); + } + + // Sort + const sortBy = pagination.sortBy || 'createdAt'; + const sortOrder = pagination.sortOrder || 'desc'; + filteredUsers.sort((a, b) => { + const aVal = (a as any)[sortBy]; + const bVal = (b as any)[sortBy]; + const comparison = aVal > bVal ? 1 : aVal < bVal ? -1 : 0; + return sortOrder === 'asc' ? comparison : -comparison; + }); + + // Paginate + const total = filteredUsers.length; + const start = (pagination.page - 1) * pagination.limit; + const end = start + pagination.limit; + const paginatedData = filteredUsers.slice(start, end); + + return { + data: paginatedData.map(u => ({ ...u })), + total, + page: pagination.page, + limit: pagination.limit, + totalPages: Math.ceil(total / pagination.limit), + }; + } + + async updateLastLogin(id: string): Promise { + const user = this.users.get(id); + if (user) { + user.lastLogin = new Date(); + user.updatedAt = new Date(); + this.users.set(id, user); + } + } + + async verifyEmail(id: string): Promise { + const user = this.users.get(id); + if (!user) return null; + + const updatedUser = { + ...user, + emailVerified: true, + updatedAt: new Date(), + }; + + this.users.set(id, updatedUser); + return { ...updatedUser }; + } + + async count(filter: UserFilter = {}): Promise { + let count = 0; + for (const user of this.users.values()) { + if (filter.role && user.role !== filter.role) continue; + if (filter.status && user.status !== filter.status) continue; + if (filter.emailVerified !== undefined && user.emailVerified !== filter.emailVerified) continue; + count++; + } + return count; + } + + async clear(): Promise { + this.users.clear(); + } +} + +export const userRepository = new UserRepository(); \ No newline at end of file