mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-26 09:20:24 -05:00
28 lines
649 B
TypeScript
28 lines
649 B
TypeScript
import { sql } from "~/db/sql";
|
|
import type { Tables } from "~/db/tables";
|
|
|
|
const stm = sql.prepare(/* sql */ `
|
|
select
|
|
"GroupMember"."userId",
|
|
"GroupMember"."role"
|
|
from "GroupMember"
|
|
where "GroupMember"."groupId" = @groupId
|
|
and "GroupMember"."role" != 'OWNER'
|
|
order by "GroupMember"."createdAt" asc
|
|
`);
|
|
|
|
export const groupSuccessorOwner = (groupId: number) => {
|
|
const rows = stm.all({ groupId }) as Array<
|
|
Pick<Tables["GroupMember"], "role" | "userId">
|
|
>;
|
|
|
|
if (rows.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
const manager = rows.find((r) => r.role === "MANAGER");
|
|
if (manager) return manager.userId;
|
|
|
|
return rows[0].userId;
|
|
};
|