import { IItem , IUser } from "@esri/arcgis-rest-types" ; import { getProp , IHubRequestOptions } from "@esri/hub-common" ; import { getTeamById } from "./get-team-by-id" ; import { ITeamStatus } from "../types" ; import { canUserCreateTeam } from "./can-user-create-team" ; import { TYPEMAP } from "./type-map" ; export param { IItem } item param { ( "core" | "content" | "followers" ) } teamType param { IUser } user param { IHubRequestOptions } ro return { * } export async function getTeamStatus ( item , teamType , user , ro ) { const result = { teamType , id : null , isOk : false , isMissing : true , isBroken : false , canFix : false , isMember : false , } ; const id = getProp ( getProp ( item , "properties" ) , TYPEMAP [ teamType ] ) ; if ( id ) { try { const group = await getTeamById ( id , ro ) ; if ( group ) { result . id = id ; result . isOk = true ; result . isMissing = false ; } else { result . id = id ; result . isBroken = true ; result . canFix = await canUserCreateTeam ( user , teamType , ro ) ; } } catch ( ex ) { result . id = id ; result . isBroken = true ; result . canFix = await canUserCreateTeam ( user , teamType , ro ) ; } } else { result . canFix = await canUserCreateTeam ( user , teamType , ro ) ; } return result ; }