|
| 1 | +import { RoomUserDAO } from "../../../../dao"; |
| 2 | +import { AbstractController, ControllerClassParams } from "../../../../abstract/controller"; |
| 3 | +import { Status } from "../../../../constants/Project"; |
| 4 | +import { Controller } from "../../../../decorator/Controller"; |
| 5 | +import { FastifySchema, Response, ResponseError } from "../../../../types/Server"; |
| 6 | + |
| 7 | +import { ServiceUserAgreement } from "../../../service/user/UserAgreement"; |
| 8 | + |
| 9 | +@Controller<RequestType, ResponseType>({ |
| 10 | + method: "get", |
| 11 | + path: "private-polic/get", |
| 12 | + auth: false, |
| 13 | + skipAutoHandle: true, |
| 14 | +}) |
| 15 | +export class AgreementGetToRtc extends AbstractController<RequestType, ResponseType> { |
| 16 | + public static readonly schema: FastifySchema<RequestType> = { |
| 17 | + querystring: { |
| 18 | + type: "object", |
| 19 | + required: ["uid"], |
| 20 | + properties: { |
| 21 | + uid: { |
| 22 | + type: "string" |
| 23 | + }, |
| 24 | + room_uuid: { |
| 25 | + type: "string" |
| 26 | + } |
| 27 | + }, |
| 28 | + }, |
| 29 | + }; |
| 30 | + |
| 31 | + public readonly svc: { |
| 32 | + userAgreement: ServiceUserAgreement; |
| 33 | + }; |
| 34 | + |
| 35 | + public constructor(params: ControllerClassParams) { |
| 36 | + super(params); |
| 37 | + |
| 38 | + this.svc = { |
| 39 | + userAgreement: new ServiceUserAgreement(this.userUUID), |
| 40 | + }; |
| 41 | + } |
| 42 | + |
| 43 | + public async execute(): Promise<Response<ResponseType>> { |
| 44 | + const rtcUidstr = this.querystring.uid; |
| 45 | + const room_uuid = this.querystring.room_uuid; |
| 46 | + const rtcUids = rtcUidstr.split(","); |
| 47 | + const listMap:Map<string, boolean> = new Map(); |
| 48 | + if (rtcUids.length > 0) { |
| 49 | + for (const rtc_uid of rtcUids) { |
| 50 | + const roomUserInfo = await RoomUserDAO().findOne(["user_uuid"], { |
| 51 | + rtc_uid, |
| 52 | + room_uuid |
| 53 | + }); |
| 54 | + if (roomUserInfo) { |
| 55 | + const bol = await ServiceUserAgreement.hasCollectData(roomUserInfo.user_uuid); |
| 56 | + if (bol) { |
| 57 | + const isAgree = await ServiceUserAgreement.isAgreeCollectData(roomUserInfo.user_uuid); |
| 58 | + listMap.set(rtc_uid, isAgree); |
| 59 | + } else { |
| 60 | + // 默认就是同意 |
| 61 | + listMap.set(rtc_uid, true); |
| 62 | + } |
| 63 | + } else { |
| 64 | + // 查不到用户则默认不同意 |
| 65 | + listMap.set(rtc_uid, false); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + return { |
| 70 | + status: Status.Success, |
| 71 | + data: Object.fromEntries(listMap) |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + public errorHandler(error: Error): ResponseError { |
| 76 | + return this.autoHandlerError(error); |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +interface RequestType { |
| 81 | + querystring: { |
| 82 | + uid: string; |
| 83 | + room_uuid: string; |
| 84 | + }; |
| 85 | +} |
| 86 | + |
| 87 | +interface ResponseType { |
| 88 | + [key: string]: boolean; |
| 89 | +} |
0 commit comments