Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -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