teams.ts
Language TypeScript1.5 KB42 lines
/*** Teams. GET /teams, confirmed against the live API.** Returns a bare array of { _id, name, companyId, project, deleted }.** No membership: there is no users, members, or userIds field, which is why* the harvest path in roster.ts is required, not a fallback. Re-check the live* response before assuming otherwise; it is cheap to check and expensive to* assume.** Meridian has three: Leadership Team, Operations Team, All Hands.*/import type { HttpClient } from './../http.js'import { RawTeamSchema, normalizeTeam, type Team } from './../types.js'export interface TeamQuery {/** Ninety models projects as teams. Excluded by default. */includeProjects?: booleanincludeDeleted?: boolean}export class TeamsResource {constructor(private readonly http: HttpClient) {}async list(q: TeamQuery = {}): Promise<Team[]> {const raw = await this.http.get('/teams')if (!Array.isArray(raw)) {throw new Error(`GET /teams did not return an array (got ${typeof raw}). Shape changed; update teams.ts.`)}const teams = raw.map((t) => normalizeTeam(RawTeamSchema.parse(t)))return teams.filter((t) => (q.includeDeleted || !t.deleted) && (q.includeProjects || !t.isProject),)}/** Name lookup for rendering, though to-dos already carry `teamName`. */async byId(): Promise<Map<string, Team>> {const teams = await this.list({ includeProjects: true, includeDeleted: true })return new Map(teams.map((t) => [t.id, t]))}}