import copy from 'fast-copy' ; import { freezeSys , toPlainObject } from 'contentful-sdk-core' ; import enhanceWithMethods from '../enhance-with-methods' ; import { wrapCollection } from '../common-utils' ; import { DefaultElements , MetaSysProps , MetaLinkProps , MakeRequest } from '../common-types' ; export type TeamProps = { /**
     * System metadata
     */ sys : MetaSysProps & { memberCount : number ; organization : { sys : MetaLinkProps ; } ; } ; /**
     * Name of the team
     */ name : string ; /**
     * Description of the team
     */ description : string ; } ; export type CreateTeamProps = Omit < TeamProps , 'sys' > ; export interface Team extends TeamProps , DefaultElements < TeamProps > { return example delete ( ) : Promise < void > ; return example update ( ) : Promise < Team > ; } private function createTeamApi ( makeRequest ) { const getParams = ( data ) => ( { teamId : data . sys . id , organizationId : data . sys . organization . sys . id , } ) ; return { update : function update ( ) { const raw = this . toPlainObject ( ) as TeamProps ; return makeRequest ( { entityType : 'Team' , action : 'update' , params : getParams ( raw ) , payload : raw , } ) . then ( ( data ) => wrapTeam ( makeRequest , data ) ) ; } , delete : function del ( ) { const raw = this . toPlainObject ( ) as TeamProps ; return makeRequest ( { entityType : 'Team' , action : 'delete' , params : getParams ( raw ) , } ) ; } , } ; } private param makeRequest param data return export function wrapTeam ( makeRequest , data ) { const team = toPlainObject ( copy ( data ) ) ; const teamWithMethods = enhanceWithMethods ( team , createTeamApi ( makeRequest ) ) ; return freezeSys ( teamWithMethods ) ; } private export const wrapTeamCollection = wrapCollection ( wrapTeam ) ;