mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-11 05:36:10 -05:00
Keep manager when morphing groups
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import { nanoid } from "nanoid";
|
||||
import { sql } from "~/db/sql";
|
||||
import { deleteLikesByGroupId } from "./deleteLikesByGroupId.server";
|
||||
import type { GroupMember, User } from "~/db/types";
|
||||
|
||||
const findToBeDeletedGroupNonRegularsStm = sql.prepare(/* sql */ `
|
||||
select "userId"
|
||||
from "GroupMember"
|
||||
where "groupId" = @groupId
|
||||
and "role" != 'REGULAR'
|
||||
`);
|
||||
|
||||
const deleteGroupStm = sql.prepare(/* sql */ `
|
||||
delete from "Group"
|
||||
@@ -35,6 +43,10 @@ export const morphGroups = sql.transaction(
|
||||
newMembers: number[];
|
||||
addChatCode: boolean;
|
||||
}) => {
|
||||
const toBeDeletedGroupNonRegulars = findToBeDeletedGroupNonRegularsStm
|
||||
.all({ groupId: otherGroupId })
|
||||
.map((row: any) => row.userId) as Array<User["id"]>;
|
||||
|
||||
deleteGroupStm.run({ groupId: otherGroupId });
|
||||
deleteGroupMapsStm.run({ groupId: otherGroupId });
|
||||
|
||||
@@ -49,10 +61,15 @@ export const morphGroups = sql.transaction(
|
||||
}
|
||||
|
||||
for (const userId of newMembers) {
|
||||
const role: GroupMember["role"] = toBeDeletedGroupNonRegulars.includes(
|
||||
userId,
|
||||
)
|
||||
? "MANAGER"
|
||||
: "REGULAR";
|
||||
addGroupMemberStm.run({
|
||||
groupId: survivingGroupId,
|
||||
userId,
|
||||
role: "REGULAR",
|
||||
role,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user