feat: enable company-wide order viewing and editing
All checks were successful
Staging Build / build (push) Successful in 3m31s

This commit is contained in:
DanielS
2026-07-04 15:41:48 +02:00
parent 149eae59c9
commit 32c2842dbd
3 changed files with 70 additions and 7 deletions

View File

@@ -508,9 +508,21 @@ export async function updateOrder(
.single()
const isAdmin = dbUser?.role === 'admin'
const isOwner = existingOrder.user_id === user.id
let isAuthorized = existingOrder.user_id === user.id
if (!isAdmin && !isOwner) {
if (!isAuthorized && dbUser?.company_id && existingOrder.user_id) {
const { data: creatorUser } = await admin
.from('users')
.select('company_id')
.eq('id', existingOrder.user_id)
.single()
if (creatorUser?.company_id === dbUser.company_id) {
isAuthorized = true
}
}
if (!isAdmin && !isAuthorized) {
throw new Error('Keine Berechtigung dieses Anfrage zu bearbeiten.')
}