v3: added multiple stylesheets, improved user profiles
This commit is contained in:
@@ -178,6 +178,44 @@ export function updateUserAvatar(userId: string, mime: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function getInviteTree(
|
||||
userId: string,
|
||||
): {
|
||||
id: string;
|
||||
username: string;
|
||||
avatarMime?: string;
|
||||
invitedById: string;
|
||||
createdAt: Date;
|
||||
}[] {
|
||||
const rows = db.prepare(`
|
||||
WITH RECURSIVE tree AS (
|
||||
SELECT id, username, avatar_mime, invited_by, created_at, 0 AS depth
|
||||
FROM users
|
||||
WHERE invited_by = ?
|
||||
UNION ALL
|
||||
SELECT u.id, u.username, u.avatar_mime, u.invited_by, u.created_at, t.depth + 1
|
||||
FROM users u
|
||||
INNER JOIN tree t ON u.invited_by = t.id
|
||||
WHERE t.depth < 10
|
||||
)
|
||||
SELECT * FROM tree ORDER BY created_at;
|
||||
`).all(userId) as {
|
||||
id: string;
|
||||
username: string;
|
||||
avatar_mime: string | null;
|
||||
invited_by: string;
|
||||
created_at: string;
|
||||
}[];
|
||||
|
||||
return rows.map((r) => ({
|
||||
id: r.id,
|
||||
username: r.username,
|
||||
avatarMime: r.avatar_mime ?? undefined,
|
||||
invitedById: r.invited_by,
|
||||
createdAt: new Date(r.created_at),
|
||||
}));
|
||||
}
|
||||
|
||||
export function deleteUser(userId: string): void {
|
||||
disconnectUser(userId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user