Added Connectwise Compnay Syncing

This commit is contained in:
2026-01-26 17:09:18 -06:00
parent 4524c0258a
commit 7748e6171b
19 changed files with 1783 additions and 9 deletions
+41
View File
@@ -0,0 +1,41 @@
import { prisma } from "../src/constants";
await (async () => {
const userIdentifier = Bun.argv[2];
const roleIdentifier = Bun.argv[3];
if (Bun.argv.length !== 4)
console.error(
"2 arguments expected. \n Format: bun utils:assign_user_role {user} {role}"
);
const user = await prisma.user.findFirst({
where: { OR: [{ id: userIdentifier }, { login: userIdentifier }] },
});
if (!user)
return console.error(
`User with identifier '${userIdentifier}' doesn't exist`
);
const role = await prisma.role.findFirst({
where: { OR: [{ id: roleIdentifier }, { moniker: roleIdentifier }] },
include: { users: true },
});
if (!role)
return console.error(
`Role with identifier '${roleIdentifier}' doesn't exist`
);
if (role.users.map((v) => v.id).includes(user.id))
return console.log("User already has role!");
await prisma.user.update({
where: { id: user.id },
data: { roles: { set: { id: role.id } } },
});
return console.log(
`User '${user.login}' has been given role '${role.title}'!`
);
})();
+27
View File
@@ -0,0 +1,27 @@
import cuid from "cuid";
import { prisma } from "../src/constants";
import { signPermissions } from "../src/modules/permission-utils/signPermissions";
let newRole;
let id = cuid();
const admin = await prisma.role.findFirst({
where: { moniker: "administrator" },
});
if (admin) console.log("Admin already exists", admin);
if (!admin)
newRole = await prisma.role.create({
data: {
id,
moniker: "administrator",
title: "Admin",
permissions: signPermissions({
issuer: "roles",
subject: id,
permissions: ["*"],
}),
},
});
console.log("Admin Role Created!", newRole);