did a whole ton of shit with calendars and roles system

This commit is contained in:
2025-10-06 23:33:29 -04:00
parent a692c15149
commit c883444de6
10 changed files with 1022 additions and 7 deletions

95
ui/src/api/roles.ts Normal file
View File

@@ -0,0 +1,95 @@
export type Role = {
id: number;
name: string;
color: string;
description: string | null;
members: any[];
};
// @ts-ignore
const addr = import.meta.env.VITE_APIHOST;
export async function getRoles(): Promise<Role[]> {
const res = await fetch(`${addr}/roles`)
if (res.ok) {
return res.json() as Promise<Role[]>;
} else {
console.error("Something went wrong approving the application")
return [];
}
}
export async function createRole(name: string, color: string, description: string | null): Promise<Role | null> {
const res = await fetch(`${addr}/roles`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
name,
color,
description
})
});
if (res.ok) {
return res.json() as Promise<Role>;
} else {
console.error("Something went wrong creating the role");
return null;
}
}
export async function addMemberToRole(member_id: number, role_id: number): Promise<boolean> {
const res = await fetch(`${addr}/memberRoles`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
member_id,
role_id
})
});
if (res.ok) {
return true;
} else {
console.error("Something went wrong adding the member to the role");
return false;
}
}
export async function removeMemberFromRole(member_id: number, role_id: number): Promise<boolean> {
const res = await fetch(`${addr}/memberRoles`, {
method: "DELETE",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
member_id,
role_id
})
});
if (res.ok) {
return true;
} else {
console.error("Something went wrong removing the member from the role");
return false;
}
}
export async function deleteRole(role_id: number): Promise<boolean> {
const res = await fetch(`${addr}/roles/${role_id}`, {
method: "DELETE"
});
if (res.ok) {
return true;
} else {
console.error("Something went wrong deleting the role");
return false;
}
}