Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/v1/controller/user/agreement/Get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { ServiceUserAgreement } from "../../../service/user/UserAgreement";
auth: true,
})
export class AgreementGet extends AbstractController<RequestType, ResponseType> {
public static readonly schema: FastifySchema<RequestType> = {
};
public static readonly schema: FastifySchema<RequestType> = {};

public readonly svc: {
userAgreement: ServiceUserAgreement;
Expand Down Expand Up @@ -41,11 +40,7 @@ export class AgreementGet extends AbstractController<RequestType, ResponseType>
}
}

interface RequestType {
querystring: {
uid: string;
};
}
interface RequestType {}

interface ResponseType {
isAgree: boolean;
Expand Down
59 changes: 40 additions & 19 deletions src/v1/controller/user/agreement/GetToRtc.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { RoomUserDAO } from "../../../../dao";
import { AbstractController, ControllerClassParams } from "../../../../abstract/controller";
import { Status } from "../../../../constants/Project";
import { Controller } from "../../../../decorator/Controller";
import { FastifySchema, Response, ResponseError } from "../../../../types/Server";

import { ServiceUserAgreement } from "../../../service/user/UserAgreement";
import { RoomUserModel } from "../../../../model/room/RoomUser";
import { dataSource } from "../../../../thirdPartyService/TypeORMService";
import { UserAgreementModel } from "./../../../../model/user/Agreement";

@Controller<RequestType, ResponseType>({
method: "get",
path: "private-polic/get",
auth: false,
skipAutoHandle: true,
skipAutoHandle: false,
enable: true
})
export class AgreementGetToRtc extends AbstractController<RequestType, ResponseType> {
public static readonly schema: FastifySchema<RequestType> = {
Expand Down Expand Up @@ -45,24 +48,42 @@ export class AgreementGetToRtc extends AbstractController<RequestType, ResponseT
const room_uuid = this.querystring.room_uuid;
const rtcUids = rtcUidstr.split(",");
const listMap:Map<string, boolean> = new Map();
if (rtcUids.length > 0) {
for (const rtc_uid of rtcUids) {
const roomUserInfo = await RoomUserDAO().findOne(["user_uuid"], {
rtc_uid,
room_uuid
});
if (roomUserInfo) {
const bol = await ServiceUserAgreement.hasCollectData(roomUserInfo.user_uuid);
if (bol) {
const isAgree = await ServiceUserAgreement.isAgreeCollectData(roomUserInfo.user_uuid);
listMap.set(rtc_uid, isAgree);
} else {
// 默认就是同意
listMap.set(rtc_uid, true);
const length = rtcUids.length;
if (length > 0) {
let i = 0;
const batchQueryRtcUids: string[][] = [];
while (i < length) {
const j = i + 50;
batchQueryRtcUids.push(rtcUids.slice(i, j));
i = j;
}
for (const rtc_uids of batchQueryRtcUids) {
const roomUsersInfos = await dataSource
.createQueryBuilder(RoomUserModel, "ru")
.where("ru.room_uuid = :room_uuid", {
room_uuid,
})
.andWhere("ru.rtc_uid IN (:...rtc_uids)", { rtc_uids })
.getMany();

for (const rtc_uid of rtc_uids) {
listMap.set(rtc_uid, false);
}
const collectInfos = await dataSource
.createQueryBuilder(UserAgreementModel, "cInfo")
.where("cInfo.user_uuid IN (:...user_uuid)", { user_uuid: roomUsersInfos.map(c=> c && c.user_uuid) })
.getMany();

for (const rInfo of roomUsersInfos) {
listMap.set(rInfo.rtc_uid, true);
const rtc_uid = rInfo.rtc_uid;
const user_uuid = rInfo.user_uuid;
if (rtc_uid && user_uuid) {
const cInfo = collectInfos.find(c=> c && (c.user_uuid === user_uuid));
if (cInfo) {
listMap.set(rtc_uid, cInfo.is_agree_collect_data);
}
}
} else {
// 查不到用户则默认不同意
listMap.set(rtc_uid, false);
}
}
}
Expand Down
51 changes: 50 additions & 1 deletion src/v1/service/user/__tests__/userAgreement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { RoomUserDAO, UserAgreementDAO } from "../../../../dao";
import { v4 } from "uuid";
import { ServiceUserAgreement } from "../UserAgreement";
import cryptoRandomString from "crypto-random-string";
import { RoomUserModel } from "../../../../model/room/RoomUser";
import { UserAgreementModel } from "../../../../model/user/Agreement";

const namespace = "[service][service-user][service-user-agreement]";

Expand Down Expand Up @@ -110,6 +112,7 @@ test(`${namespace} - get user by rtc_uuid collect agreement`, async ava => {
const userUUID = v4();
const roomUUID = v4();
const rtcUUID = cryptoRandomString({ length: 6, type: "numeric" });
const rtcUUID1 = cryptoRandomString({ length: 6, type: "numeric" });

await Promise.all([
RoomUserDAO().insert({
Expand All @@ -132,12 +135,58 @@ test(`${namespace} - get user by rtc_uuid collect agreement`, async ava => {

ava.is(result?.user_uuid, userUUID);

const result1 = await UserAgreementDAO().findOne(["user_uuid"], {
const result1 = await UserAgreementDAO().findOne(["user_uuid", "is_agree_collect_data"], {
user_uuid: userUUID,
});

ava.not(result1, undefined);

ava.is(result?.user_uuid, result1?.user_uuid);

const rtcUids = [rtcUUID, rtcUUID1];
const length = rtcUids.length;
const listMap:Map<string, boolean> = new Map();
if (length > 0) {
let i = 0;
const batchQueryRtcUids: string[][] = [];
while (i < length) {
const j = i + 50;
batchQueryRtcUids.push(rtcUids.slice(i, j));
i = j;
}
for (const rtc_uids of batchQueryRtcUids) {
const roomUsersInfos = await dataSource
.createQueryBuilder(RoomUserModel, "ru")
.where("ru.room_uuid = :room_uuid", {
room_uuid:roomUUID,
})
.andWhere("ru.rtc_uid IN (:...rtc_uids)", { rtc_uids })
.getMany();

for (const rtc_uid of rtc_uids) {
listMap.set(rtc_uid, false);
}
const collectInfos = await dataSource
.createQueryBuilder(UserAgreementModel, "cInfo")
.where("cInfo.user_uuid IN (:...user_uuid)", { user_uuid: roomUsersInfos.map(c=> c && c.user_uuid) })
.getMany();

for (const rInfo of roomUsersInfos) {
listMap.set(rInfo.rtc_uid, true);
const rtc_uid = rInfo.rtc_uid;
const user_uuid = rInfo.user_uuid;
if (rtc_uid && user_uuid) {
const cInfo = collectInfos.find(c=> c && (c.user_uuid === user_uuid));
if (cInfo) {
listMap.set(rtc_uid, cInfo.is_agree_collect_data);
}
}
}
}
}
const obj = Object.fromEntries(listMap);

ava.is(result1?.is_agree_collect_data, obj?.[rtcUUID]);

ava.is(false, obj?.[rtcUUID1]);
});