feat(F-048): completed feature

This commit is contained in:
chattie
2026-08-19 07:17:14 +02:00
parent 8ee1938af9
commit 835ab66eda
187 changed files with 12361 additions and 1065 deletions

View File

@@ -73,14 +73,26 @@ export class PgUserRepository implements UserRepository {
return { id: row.id, email: row.email, role: row.role, createdAt: row.created_at };
}
async listUsers(params?: { limit?: number; offset?: number; role?: string; q?: string }): Promise<{ items: User[]; total: number }> {
async listUsers(params?: {
limit?: number;
offset?: number;
role?: string;
q?: string;
}): Promise<{ items: User[]; total: number }> {
const limit = params?.limit ?? 20;
const offset = params?.offset ?? 0;
const conditions: string[] = [];
const values: unknown[] = [];
let i = 1;
if (params?.role) { conditions.push(`role = $${i++}`); values.push(params.role); }
if (params?.q) { conditions.push(`(email ILIKE $${i++} OR role ILIKE $${i++})`); values.push(`%${params.q}%`); values.push(`%${params.q}%`); }
if (params?.role) {
conditions.push(`role = $${i++}`);
values.push(params.role);
}
if (params?.q) {
conditions.push(`(email ILIKE $${i++} OR role ILIKE $${i++})`);
values.push(`%${params.q}%`);
values.push(`%${params.q}%`);
}
const where = conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
const countResult = await this.pool.query<{ count: string }>(
`SELECT COUNT(*) FROM identity_users ${where}`,
@@ -92,7 +104,12 @@ export class PgUserRepository implements UserRepository {
[...values, limit, offset],
);
return {
items: rows.rows.map((r) => ({ id: r.id, email: r.email, role: r.role, createdAt: r.created_at })),
items: rows.rows.map((r) => ({
id: r.id,
email: r.email,
role: r.role,
createdAt: r.created_at,
})),
total,
};
}
@@ -101,8 +118,14 @@ export class PgUserRepository implements UserRepository {
const sets: string[] = [];
const values: unknown[] = [];
let i = 1;
if (patch.role) { sets.push(`role = $${i++}`); values.push(patch.role); }
if (patch.passwordHash) { sets.push(`password_hash = $${i++}`); values.push(patch.passwordHash); }
if (patch.role) {
sets.push(`role = $${i++}`);
values.push(patch.role);
}
if (patch.passwordHash) {
sets.push(`password_hash = $${i++}`);
values.push(patch.passwordHash);
}
if (!sets.length) {
const existing = await this.findById(id);
if (!existing) throw new Error('User not found');