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 TeamMembershipProps = { /**
     * System metadata
     */ sys : MetaSysProps & { team : { sys : MetaLinkProps ; } ; organization : { sys : MetaLinkProps ; } ; organizationMembership : { sys : MetaLinkProps ; } ; } ; /**
     * Is admin
     */ admin : boolean ; /**
     * Organization membership id
     */ organizationMembershipId : string ; } ; export type CreateTeamMembershipProps = Omit < TeamMembershipProps , 'sys' > ; export interface TeamMembership extends TeamMembershipProps , DefaultElements < TeamMembershipProps > { return example delete ( ) : Promise < void > ; return example update ( ) : Promise < TeamMembership > ; } private function createTeamMembershipApi ( makeRequest ) { const getParams = ( data ) => ( { teamMembershipId : data . sys . id , teamId : data . sys . team . sys . id , organizationId : data . sys . organization . sys . id , } ) ; return { update : function ( ) { const raw = this . toPlainObject ( ) as TeamMembershipProps ; return makeRequest ( { entityType : 'TeamMembership' , action : 'update' , params : getParams ( raw ) , payload : raw , } ) . then ( ( data ) => wrapTeamMembership ( makeRequest , data ) ) ; } , delete : function del ( ) { const raw = this . toPlainObject ( ) as TeamMembershipProps ; return makeRequest ( { entityType : 'TeamMembership' , action : 'delete' , params : getParams ( raw ) , } ) ; } , } ; } private param makeRequest param data return export function wrapTeamMembership ( makeRequest , data ) { const teamMembership = toPlainObject ( copy ( data ) ) ; const teamMembershipWithMethods = enhanceWithMethods ( teamMembership , createTeamMembershipApi ( makeRequest ) ) ; return freezeSys ( teamMembershipWithMethods ) ; } private export const wrapTeamMembershipCollection = wrapCollection ( wrapTeamMembership ) ;