Rollen Chunk 6: Team-Tab mit Matrix-Kalender und Genehmigungen
This commit is contained in:
1 parent
89ebd49c1c
commit
ce5368de4a
1 file changed
+42
@@ -80,6 +80,48 @@ export function userExists(db: Db, userId: string): boolean {
|
||||
return row !== undefined;
|
||||
}
|
||||
|
||||
export interface TeamUser {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
role: UserRole;
|
||||
}
|
||||
|
||||
export function listAllUsers(db: Db): TeamUser[] {
|
||||
const rows = db
|
||||
.prepare(
|
||||
'SELECT id, name, email, role FROM "user" WHERE banned IS NOT 1 ORDER BY createdAt',
|
||||
)
|
||||
.all() as { id: string; name: string; email: string; role: string | null }[];
|
||||
return rows.map((row) => ({
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
email: row.email,
|
||||
role:
|
||||
row.role === "admin" || row.role === "teamleiter"
|
||||
? row.role
|
||||
: "benutzer",
|
||||
}));
|
||||
}
|
||||
|
||||
export function setVacationStatus(
|
||||
db: Db,
|
||||
userId: string,
|
||||
id: number,
|
||||
status: VacationStatus,
|
||||
): boolean {
|
||||
// Nur offene Anfragen entscheiden; bestätigte gehen über den Papierkorb.
|
||||
if (status !== "bestätigt" && status !== "abgelehnt") {
|
||||
return false;
|
||||
}
|
||||
const result = db
|
||||
.prepare(
|
||||
"UPDATE vacation_requests SET status = ? WHERE id = ? AND user_id = ? AND status = 'beantragt' AND deleted_at IS NULL",
|
||||
)
|
||||
.run(status, id, userId);
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
||||
export type UserRole = "admin" | "teamleiter" | "benutzer";
|
||||
|
||||
export function getUserRole(db: Db, userId: string): UserRole {
|
||||
|
||||
Reference in new issue
Block a user