11import _ from 'lodash'
22import { axiosInstance as axios } from './requestInterceptor'
3- import { TC_API_URL } from '../config/constants'
3+ import { TC_API_URL , CONNECT_MESSAGE_API_URL } from '../config/constants'
44
55export function getMembersById ( userIds ) {
66 const _userIdArr = _ . map ( userIds , _id => `userId:${ _id } ` )
@@ -29,7 +29,9 @@ export function addProjectMember(projectId, newMember) {
2929 const url = `${ TC_API_URL } /v4/projects/${ projectId } /members/`
3030 return axios . post ( url , { param : newMember } )
3131 . then ( resp => {
32- return resp . data . result . content
32+ return axios . put ( `${ CONNECT_MESSAGE_API_URL } /v4/topics/syncUsers` ,
33+ { reference : 'project' , referenceId : projectId } )
34+ . then ( ( ) => resp . data . result . content )
3335 } )
3436}
3537
@@ -42,11 +44,23 @@ export function updateProjectMember(projectId, memberId, updatedProps) {
4244 } )
4345}
4446
45- export function removeProjectMember ( projectId , memberId ) {
47+ export function removeProjectMember ( projectId , memberId , isUserLeaving ) {
4648 const url = `${ TC_API_URL } /v4/projects/${ projectId } /members/${ memberId } /`
47- return axios . delete ( url )
48- . then ( resp => { // eslint-disable-line no-unused-vars
49- // return the member id just removed
50- return memberId
49+ let promise = { then : fn => fn ( ) }
50+ if ( isUserLeaving ) {
51+ promise = axios . put ( `${ CONNECT_MESSAGE_API_URL } /v4/topics/syncUsers` ,
52+ { reference : 'project' , referenceId : projectId , isUserLeaving } )
53+ }
54+ return promise . then ( ( ) => {
55+ return axios . delete ( url )
56+ . then ( ( ) => {
57+ if ( ! isUserLeaving ) {
58+ return axios . put ( `${ CONNECT_MESSAGE_API_URL } /v4/topics/syncUsers` ,
59+ { reference : 'project' , referenceId : projectId } )
60+ . then ( ( ) => memberId )
61+ }
62+ // return the member id just removed
63+ return memberId
64+ } )
5165 } )
5266}
0 commit comments