fix(auth): fix listMembers response shape and updateMember role sync
- listMembers was returning { data, total } but frontend expects TenantMember[]
directly, causing members.map is not a function crash on the detail page.
- updateMember now also syncs role changes to public.users so the new role
takes effect the next time the user logs in (JWT is generated from public.users).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6e50f4cc50
commit
e48615e713
|
|
@ -170,14 +170,13 @@ export class TenantController {
|
||||||
const rows = await qr.query(
|
const rows = await qr.query(
|
||||||
`SELECT id, email, name, roles, is_active, created_at FROM users ORDER BY created_at ASC`,
|
`SELECT id, email, name, roles, is_active, created_at FROM users ORDER BY created_at ASC`,
|
||||||
);
|
);
|
||||||
const data = rows.map((row: any) => ({
|
return rows.map((row: any) => ({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
email: row.email,
|
email: row.email,
|
||||||
name: row.name,
|
name: row.name,
|
||||||
role: this.parseRole(row.roles),
|
role: this.parseRole(row.roles),
|
||||||
joinedAt: row.created_at,
|
joinedAt: row.created_at,
|
||||||
}));
|
}));
|
||||||
return { data, total: data.length };
|
|
||||||
} finally {
|
} finally {
|
||||||
await qr.release();
|
await qr.release();
|
||||||
}
|
}
|
||||||
|
|
@ -230,6 +229,13 @@ export class TenantController {
|
||||||
`UPDATE users SET ${updates.join(', ')} WHERE id = $${idx}`,
|
`UPDATE users SET ${updates.join(', ')} WHERE id = $${idx}`,
|
||||||
params,
|
params,
|
||||||
);
|
);
|
||||||
|
// Sync role change to public.users so it takes effect on next login
|
||||||
|
if (body.role) {
|
||||||
|
await this.dataSource.query(
|
||||||
|
`UPDATE public.users SET roles = $1, updated_at = NOW() WHERE id = $2`,
|
||||||
|
[[body.role], memberId],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updated = await qr.query(
|
const updated = await qr.query(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue