Skip to content

Commit 61658c8

Browse files
authored
fix: fix when empty userUuids can not query IN (#854)
1 parent cec8c64 commit 61658c8

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/v1/controller/user/agreement/GetToRtc.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@ export class AgreementGetToRtc extends AbstractController<RequestType, ResponseT
5656
const batchedRtcUids = rtcUids.slice(i, j);
5757
const roomUserInfos = await this.getRoomUserInfos(room_uuid, batchedRtcUids);
5858
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);
59+
if (userUuids.length > 0) {
60+
const userAgreements = await this.getUserAgreements(userUuids);
61+
for (const userInfo of roomUserInfos) {
62+
const { rtc_uid, user_uuid } = userInfo;
63+
const userAgreement = userAgreements.find(ua => ua.user_uuid === user_uuid);
64+
if (userAgreement) {
65+
userAgreementMap.set(rtc_uid, userAgreement.is_agree_collect_data);
66+
} else {
67+
userAgreementMap.set(rtc_uid, true);
68+
}
6769
}
6870
}
6971
i = j;
@@ -74,7 +76,6 @@ export class AgreementGetToRtc extends AbstractController<RequestType, ResponseT
7476
data: Object.fromEntries(userAgreementMap)
7577
}
7678
}
77-
7879

7980
private async getRoomUserInfos(room_uuid: string, rtc_uids: string[]): Promise<RoomUserModel[]> {
8081
return dataSource

src/v1/service/user/__tests__/userAgreement.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,19 @@ test(`${namespace} - get user by rtc_uuid collect agreement`, async ava => {
157157
.andWhere("ru.rtc_uid IN (:...rtc_uids)", { rtc_uids: batchedRtcUids })
158158
.getMany();
159159
const userUuids = roomUserInfos.map(user => user.user_uuid);
160-
const userAgreements = await dataSource
161-
.createQueryBuilder(UserAgreementModel, "ua")
162-
.where("ua.user_uuid IN (:...userUuids)", { userUuids })
163-
.getMany();;
164-
for (const userInfo of roomUserInfos) {
165-
const { rtc_uid, user_uuid } = userInfo;
166-
const userAgreement = userAgreements.find(ua => ua.user_uuid === user_uuid);
167-
if (userAgreement) {
168-
userAgreementMap.set(rtc_uid, userAgreement.is_agree_collect_data);
169-
} else {
170-
userAgreementMap.set(rtc_uid, true);
160+
if (userUuids.length > 0) {
161+
const userAgreements = await dataSource
162+
.createQueryBuilder(UserAgreementModel, "ua")
163+
.where("ua.user_uuid IN (:...userUuids)", { userUuids })
164+
.getMany();;
165+
for (const userInfo of roomUserInfos) {
166+
const { rtc_uid, user_uuid } = userInfo;
167+
const userAgreement = userAgreements.find(ua => ua.user_uuid === user_uuid);
168+
if (userAgreement) {
169+
userAgreementMap.set(rtc_uid, userAgreement.is_agree_collect_data);
170+
} else {
171+
userAgreementMap.set(rtc_uid, true);
172+
}
171173
}
172174
}
173175
i = j;

0 commit comments

Comments
 (0)