Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+64
@@ -0,0 +1,64 @@
|
||||
import { db } from "~/utils/db.server";
|
||||
|
||||
export async function createUserGroup(userId: string, groupId: string) {
|
||||
return await db.groupUser.create({
|
||||
data: {
|
||||
userId,
|
||||
groupId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function createUserGroups(groupId: string, userIds: string[]) {
|
||||
const uniqueUserIds = [...new Set(userIds)];
|
||||
if (uniqueUserIds.length === 0) {
|
||||
return { count: 0 };
|
||||
}
|
||||
return await db.groupUser.createMany({
|
||||
data: uniqueUserIds.map((userId) => ({
|
||||
userId,
|
||||
groupId,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteUserGroup(userId: string, groupId: string) {
|
||||
return await db.groupUser.deleteMany({
|
||||
where: {
|
||||
userId,
|
||||
groupId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function replaceGroupUsers(groupId: string, tenantId: string, userIds: string[]) {
|
||||
const uniqueUserIds = [...new Set(userIds)];
|
||||
return await db.$transaction(async (tx) => {
|
||||
await tx.groupUser.deleteMany({
|
||||
where: {
|
||||
groupId,
|
||||
group: { tenantId },
|
||||
},
|
||||
});
|
||||
if (uniqueUserIds.length === 0) {
|
||||
return { count: 0 };
|
||||
}
|
||||
return await tx.groupUser.createMany({
|
||||
data: uniqueUserIds.map((userId) => ({
|
||||
userId,
|
||||
groupId,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteGroupUsers(groupId: string, tenantId: string) {
|
||||
return await db.groupUser.deleteMany({
|
||||
where: {
|
||||
groupId,
|
||||
group: { tenantId },
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user