23 lines
786 B
JavaScript
23 lines
786 B
JavaScript
import { getEmployeeByEmail, getEmployeeByUserId } from './appwriteAdmin.js'
|
|
|
|
/**
|
|
* Ticketsystem-Mitarbeiter (employees-Collection) oder Appwrite-Label "admin" -> Admin-Ansicht im Portal.
|
|
* isAdmin = Label "admin"; null = kein Mitarbeiter.
|
|
*/
|
|
export async function resolveStaffAccount(appwriteUserId, email, account) {
|
|
const isAdmin = Array.isArray(account?.labels) && account.labels.includes('admin')
|
|
|
|
let employee = await getEmployeeByUserId(appwriteUserId).catch(() => null)
|
|
if (!employee) {
|
|
employee = await getEmployeeByEmail(account?.email || email).catch(() => null)
|
|
}
|
|
|
|
if (!employee && !isAdmin) return null
|
|
|
|
return {
|
|
isAdmin,
|
|
name: employee?.displayName || account?.name || 'Mitarbeiter',
|
|
email: account?.email || employee?.email || email,
|
|
}
|
|
}
|