feat: add kitchen dashboard, format codebase

This commit is contained in:
2025-12-02 17:00:17 +01:00
parent 2a9956c3e6
commit 5ce1b4728b
82 changed files with 5206 additions and 3134 deletions

View File

@@ -1,42 +1,44 @@
import type { User } from '@/payload-types'
import type { Access, Where } from 'payload'
import { getTenantFromCookie } from '@payloadcms/plugin-multi-tenant/utilities'
import type { User } from "@/payload-types";
import type { Access, Where } from "payload";
import { getTenantFromCookie } from "@payloadcms/plugin-multi-tenant/utilities";
import { isSuperAdmin } from '../../../access/isSuperAdmin'
import { getUserTenantIDs } from '../../../utilities/getUserTenantIDs'
import { isAccessingSelf } from './isAccessingSelf'
import { getCollectionIDType } from '@/utilities/getCollectionIDType'
import { isSuperAdmin } from "../../../access/isSuperAdmin";
import { getUserTenantIDs } from "../../../utilities/getUserTenantIDs";
import { isAccessingSelf } from "./isAccessingSelf";
import { getCollectionIDType } from "@/utilities/getCollectionIDType";
export const readAccess: Access<User> = ({ req, id }) => {
if (!req?.user) {
return false
return false;
}
if (isAccessingSelf({ id, user: req.user })) {
return true
return true;
}
const superAdmin = isSuperAdmin(req.user)
const superAdmin = isSuperAdmin(req.user);
const selectedTenant = getTenantFromCookie(
req.headers,
getCollectionIDType({ payload: req.payload, collectionSlug: 'tenants' }),
)
const adminTenantAccessIDs = getUserTenantIDs(req.user, 'admin')
getCollectionIDType({ payload: req.payload, collectionSlug: "tenants" }),
);
const adminTenantAccessIDs = getUserTenantIDs(req.user, "admin");
if (selectedTenant) {
// If it's a super admin, or they have access to the tenant ID set in cookie
const hasTenantAccess = adminTenantAccessIDs.some((id) => id === selectedTenant)
const hasTenantAccess = adminTenantAccessIDs.some(
(id) => id === selectedTenant,
);
if (superAdmin || hasTenantAccess) {
return {
'tenants.tenant': {
"tenants.tenant": {
equals: selectedTenant,
},
}
};
}
}
if (superAdmin) {
return true
return true;
}
return {
@@ -47,10 +49,10 @@ export const readAccess: Access<User> = ({ req, id }) => {
},
},
{
'tenants.tenant': {
"tenants.tenant": {
in: adminTenantAccessIDs,
},
},
],
} as Where
}
} as Where;
};