Filter Workforce departments to the configured location

getAllDepartments() was pulling every department across all Workforce
locations, not just this hotel's — mirrors the location_id filter wages'
fetchAllDepartments() already uses.
This commit is contained in:
jtricerolph 2026-07-26 09:05:04 +00:00
parent ca0dc9b070
commit d6542f4503

View file

@ -58,7 +58,10 @@ export async function findEmployeeByEmail(email) {
export async function getAllDepartments() {
if (_deptsCache && Date.now() < _deptsCache.expires_at) return _deptsCache.depts
const depts = await wfFetchPaged('/api/v2/departments')
const creds = await getWorkforceCreds()
const locationId = creds.location_id ? String(creds.location_id) : null
const all = await wfFetchPaged('/api/v2/departments')
const depts = locationId ? all.filter(d => String(d.location_id) === locationId) : all
_deptsCache = { depts, expires_at: Date.now() + 5 * 60_000 }
return depts
}