Production
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import type { AreaManagerMapping, Headquarters, User } from "../types";
|
||||
|
||||
/** Headquarters a person works in: an MR has one, an AM has any number, GM and Admin cover all. */
|
||||
export function headquartersOf(user: User, hqs: Headquarters[], mappings: AreaManagerMapping[]): { all: boolean; items: Headquarters[] } {
|
||||
if (user.role === "GM" || user.role === "ADMIN") return { all: true, items: [] };
|
||||
const ids = user.role === "MR"
|
||||
? (user.headquarters_id ? [user.headquarters_id] : [])
|
||||
: mappings.filter((m) => m.area_manager_user_id === user.id).map((m) => m.headquarters_id);
|
||||
const wanted = new Set(ids);
|
||||
return { all: false, items: hqs.filter((h) => wanted.has(h.id)) };
|
||||
}
|
||||
Reference in New Issue
Block a user