mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 14:16:34 +09:00
🔖 Checkpoint: Edit /workspaces/claude-code-flow/user-service/src/repositories/user.repository.ts
This commit is contained in:
1 parent
241780df63
commit
8ff1c37223
3 files changed
+180
No files matched your search
@@ -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"}
|
||||
@@ -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(-) "}
|
||||
@@ -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<string, User> = new Map();
|
||||
|
||||
async create(data: CreateUserDTO): Promise<User> {
|
||||
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<User | null> {
|
||||
const user = this.users.get(id);
|
||||
return user ? { ...user } : null;
|
||||
}
|
||||
|
||||
async findByEmail(email: string): Promise<User | null> {
|
||||
for (const user of this.users.values()) {
|
||||
if (user.email.toLowerCase() === email.toLowerCase()) {
|
||||
return { ...user };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async findByUsername(username: string): Promise<User | null> {
|
||||
for (const user of this.users.values()) {
|
||||
if (user.username.toLowerCase() === username.toLowerCase()) {
|
||||
return { ...user };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async update(id: string, data: UpdateUserDTO): Promise<User | null> {
|
||||
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<boolean> {
|
||||
return this.users.delete(id);
|
||||
}
|
||||
|
||||
async softDelete(id: string): Promise<User | null> {
|
||||
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<PaginatedResult<User>> {
|
||||
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<void> {
|
||||
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<User | null> {
|
||||
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<number> {
|
||||
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<void> {
|
||||
this.users.clear();
|
||||
}
|
||||
}
|
||||
|
||||
export const userRepository = new UserRepository();
|
||||
Reference in new issue
Block a user