@@ -47,52 +47,49 @@ export class AgreementGetToRtc extends AbstractController<RequestType, ResponseT
4747 const rtcUidstr = this . querystring . uid ;
4848 const room_uuid = this . querystring . room_uuid ;
4949 const rtcUids = rtcUidstr . split ( "," ) ;
50- const listMap :Map < string , boolean > = new Map ( ) ;
50+ const userAgreementMap :Map < string , boolean > = new Map ( rtcUids . map ( rtc_uid => [ rtc_uid , false ] ) ) ;
5151 const length = rtcUids . length ;
5252 if ( length > 0 ) {
5353 let i = 0 ;
54- const batchQueryRtcUids : string [ ] [ ] = [ ] ;
5554 while ( i < length ) {
5655 const j = i + 50 ;
57- batchQueryRtcUids . push ( rtcUids . slice ( i , j ) ) ;
58- i = j ;
59- }
60- for ( const rtc_uids of batchQueryRtcUids ) {
61- const roomUsersInfos = await dataSource
62- . createQueryBuilder ( RoomUserModel , "ru" )
63- . where ( "ru.room_uuid = :room_uuid" , {
64- room_uuid,
65- } )
66- . andWhere ( "ru.rtc_uid IN (:...rtc_uids)" , { rtc_uids } )
67- . getMany ( ) ;
68-
69- for ( const rtc_uid of rtc_uids ) {
70- listMap . set ( rtc_uid , false ) ;
71- }
72- const collectInfos = await dataSource
73- . createQueryBuilder ( UserAgreementModel , "cInfo" )
74- . where ( "cInfo.user_uuid IN (:...user_uuid)" , { user_uuid : roomUsersInfos . map ( c => c && c . user_uuid ) } )
75- . getMany ( ) ;
76-
77- for ( const rInfo of roomUsersInfos ) {
78- listMap . set ( rInfo . rtc_uid , true ) ;
79- const rtc_uid = rInfo . rtc_uid ;
80- const user_uuid = rInfo . user_uuid ;
81- if ( rtc_uid && user_uuid ) {
82- const cInfo = collectInfos . find ( c => c && ( c . user_uuid === user_uuid ) ) ;
83- if ( cInfo ) {
84- listMap . set ( rtc_uid , cInfo . is_agree_collect_data ) ;
85- }
56+ const batchedRtcUids = rtcUids . slice ( i , j ) ;
57+ const roomUserInfos = await this . getRoomUserInfos ( room_uuid , batchedRtcUids ) ;
58+ const userUuids = roomUserInfos . map ( user => user . user_uuid ) ;
59+ const userAgreements = await this . getUserAgreements ( userUuids ) ;
60+ for ( const userInfo of roomUserInfos ) {
61+ const { rtc_uid, user_uuid } = userInfo ;
62+ const userAgreement = userAgreements . find ( ua => ua . user_uuid === user_uuid ) ;
63+ if ( userAgreement ) {
64+ userAgreementMap . set ( rtc_uid , userAgreement . is_agree_collect_data ) ;
65+ } else {
66+ userAgreementMap . set ( rtc_uid , true ) ;
8667 }
8768 }
69+ i = j ;
8870 }
8971 }
9072 return {
9173 status : Status . Success ,
92- data : Object . fromEntries ( listMap )
74+ data : Object . fromEntries ( userAgreementMap )
9375 }
9476 }
77+
9578
79+ private async getRoomUserInfos ( room_uuid : string , rtc_uids : string [ ] ) : Promise < RoomUserModel [ ] > {
80+ return dataSource
81+ . createQueryBuilder ( RoomUserModel , "ru" )
82+ . where ( "ru.room_uuid = :room_uuid" , { room_uuid } )
83+ . andWhere ( "ru.rtc_uid IN (:...rtc_uids)" , { rtc_uids } )
84+ . getMany ( ) ;
85+ }
86+ private async getUserAgreements ( userUuids : string [ ] ) : Promise < UserAgreementModel [ ] > {
87+ return dataSource
88+ . createQueryBuilder ( UserAgreementModel , "ua" )
89+ . where ( "ua.user_uuid IN (:...userUuids)" , { userUuids } )
90+ . getMany ( ) ;
91+ }
92+
9693 public errorHandler ( error : Error ) : ResponseError {
9794 return this . autoHandlerError ( error ) ;
9895 }
0 commit comments