mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-25 07:32:19 -05:00
44 lines
1019 B
TypeScript
44 lines
1019 B
TypeScript
import { sql } from "~/db/sql";
|
|
import type { Tables } from "~/db/tables";
|
|
import { parseDBJsonArray } from "~/utils/sql";
|
|
|
|
const stm = sql.prepare(/* sql */ `
|
|
select
|
|
"Group"."id",
|
|
"Group"."status",
|
|
json_group_array(
|
|
json_object(
|
|
'id', "User"."id",
|
|
'username', "User"."username",
|
|
'role', "GroupMember"."role"
|
|
)
|
|
) as "members"
|
|
from
|
|
"Group"
|
|
left join "GroupMember" on "GroupMember"."groupId" = "Group"."id"
|
|
left join "User" on "User"."id" = "GroupMember"."userId"
|
|
where
|
|
"Group"."inviteCode" = @inviteCode
|
|
and "Group"."status" != 'INACTIVE'
|
|
group by "Group"."id"
|
|
`);
|
|
|
|
export function findGroupByInviteCode(inviteCode: string): {
|
|
id: number;
|
|
status: Tables["Group"]["status"];
|
|
members: {
|
|
id: number;
|
|
username: string;
|
|
role: Tables["GroupMember"]["role"];
|
|
}[];
|
|
} | null {
|
|
const row = stm.get({ inviteCode }) as any;
|
|
if (!row) return null;
|
|
|
|
return {
|
|
id: row.id,
|
|
status: row.status,
|
|
members: parseDBJsonArray(row.members),
|
|
};
|
|
}
|