'use strict' ; import BaseModel from '../bases/BaseModel' ; import { nobodyUrl } from '../config/config' ; import { IMemberData } from 'teambition' ; class MemberModel extends BaseModel { public getMemberCollection ( projectId ) { return this . _get < { [ index ] : IMemberData ; } > ( 'members' , projectId ) ; } public setMemberCollection ( projectId , collection ) { let cache = this . getMemberCollection ( projectId ) ; if ( ! cache ) { let memberMap ; memberMap = { } ; angular . forEach ( collection , ( member ) => { memberMap [ member . _id ] = member ; } ) ; memberMap [ '0' ] = { _id : '0' , name : '待认领' , avatarUrl : nobodyUrl } ; this . _set ( 'members' , projectId , memberMap ) ; return memberMap ; } else { return cache ; } } public setOrganizationMembers ( organizationId , members ) { let cache = this . getOrganizationMembers ( organizationId ) ; if ( ! cache ) { let memberData ; memberData = { } ; angular . forEach ( members , ( member ) => { memberData [ member . _id ] = member ; } ) ; this . _set ( 'members:organization' , organizationId , memberData ) ; return memberData ; } else { return cache ; } } public getOrganizationMembers ( organizationId ) { return this . _get < { [ index ] : IMemberData ; } > ( 'members:organization' , organizationId ) ; } public addMember ( projectId , member ) { let cache = this . getMemberCollection ( projectId ) ; if ( cache && ! cache [ member . _id ] ) { cache [ member . _id ] = member ; } } } export default new MemberModel ( ) ;