backend: enhance recording and room repositories with additional filtering options
This commit is contained in:
parent
1c955c60d0
commit
f5b805f3a3
@ -1,4 +1,4 @@
|
||||
import { MeetRecordingInfo, MeetRecordingStatus } from '@openvidu-meet/typings';
|
||||
import { MeetRecordingFilters, MeetRecordingInfo, MeetRecordingStatus } from '@openvidu-meet/typings';
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { uid as secureUid } from 'uid/secure';
|
||||
import { MeetRecordingDocument, MeetRecordingModel } from '../models/mongoose-schemas/recording.schema.js';
|
||||
@ -90,27 +90,29 @@ export class RecordingRepository<TRecording extends MeetRecordingInfo = MeetReco
|
||||
* @param options - Query options
|
||||
* @param options.roomId - Optional room ID for exact match filtering
|
||||
* @param options.roomName - Optional room name for regex match filtering (case-insensitive)
|
||||
* @param options.status - Optional recording status to filter by
|
||||
* @param options.fields - Comma-separated list of fields to include in the result
|
||||
* @param options.maxItems - Maximum number of results to return (default: 10)
|
||||
* @param options.nextPageToken - Token for pagination (encoded cursor with last sortField value and _id)
|
||||
* @param options.sortField - Field to sort by (default: 'startDate')
|
||||
* @param options.sortOrder - Sort order: 'asc' or 'desc' (default: 'desc')
|
||||
* @returns Object containing recordings array, pagination info, and optional next page token
|
||||
*/
|
||||
async find(
|
||||
options: {
|
||||
roomId?: string;
|
||||
roomName?: string;
|
||||
maxItems?: number;
|
||||
nextPageToken?: string;
|
||||
sortField?: string;
|
||||
sortOrder?: 'asc' | 'desc';
|
||||
} = {}
|
||||
): Promise<{
|
||||
async find(options: MeetRecordingFilters = {}): Promise<{
|
||||
recordings: TRecording[];
|
||||
isTruncated: boolean;
|
||||
nextPageToken?: string;
|
||||
}> {
|
||||
const { roomId, roomName, maxItems = 10, nextPageToken, sortField = 'startDate', sortOrder = 'desc' } = options;
|
||||
const {
|
||||
roomId,
|
||||
roomName,
|
||||
status,
|
||||
fields,
|
||||
maxItems = 10,
|
||||
nextPageToken,
|
||||
sortField = 'startDate',
|
||||
sortOrder = 'desc'
|
||||
} = options;
|
||||
|
||||
// Build base filter
|
||||
const filter: Record<string, unknown> = {};
|
||||
@ -126,6 +128,10 @@ export class RecordingRepository<TRecording extends MeetRecordingInfo = MeetReco
|
||||
filter.roomName = new RegExp(roomName, 'i');
|
||||
}
|
||||
|
||||
if (status) {
|
||||
filter.status = status;
|
||||
}
|
||||
|
||||
// Use base repository's pagination method
|
||||
const result = await this.findMany(filter, {
|
||||
maxItems,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { MeetRoom, MeetRoomStatus } from '@openvidu-meet/typings';
|
||||
import { MeetRoom, MeetRoomFilters, MeetRoomStatus } from '@openvidu-meet/typings';
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { MeetRoomDocument, MeetRoomModel } from '../models/mongoose-schemas/room.schema.js';
|
||||
import { LoggerService } from '../services/logger.service.js';
|
||||
@ -76,26 +76,28 @@ export class RoomRepository<TRoom extends MeetRoom = MeetRoom> extends BaseRepos
|
||||
*
|
||||
* @param options - Query options
|
||||
* @param options.roomName - Optional room name to filter by (case-insensitive partial match)
|
||||
* @param options.status - Optional room status to filter by
|
||||
* @param options.fields - Comma-separated list of fields to include in the result
|
||||
* @param options.maxItems - Maximum number of results to return (default: 100)
|
||||
* @param options.nextPageToken - Token for pagination (encoded cursor with last sortField value and _id)
|
||||
* @param options.sortField - Field to sort by (default: 'createdAt')
|
||||
* @param options.sortField - Field to sort by (default: 'creationDate')
|
||||
* @param options.sortOrder - Sort order: 'asc' or 'desc' (default: 'desc')
|
||||
* @returns Object containing rooms array, pagination info, and optional next page token
|
||||
*/
|
||||
async find(
|
||||
options: {
|
||||
roomName?: string;
|
||||
maxItems?: number;
|
||||
nextPageToken?: string;
|
||||
sortField?: string;
|
||||
sortOrder?: 'asc' | 'desc';
|
||||
} = {}
|
||||
): Promise<{
|
||||
async find(options: MeetRoomFilters = {}): Promise<{
|
||||
rooms: TRoom[];
|
||||
isTruncated: boolean;
|
||||
nextPageToken?: string;
|
||||
}> {
|
||||
const { roomName, maxItems = 100, nextPageToken, sortField = 'creationDate', sortOrder = 'desc' } = options;
|
||||
const {
|
||||
roomName,
|
||||
status,
|
||||
fields,
|
||||
maxItems = 100,
|
||||
nextPageToken,
|
||||
sortField = 'creationDate',
|
||||
sortOrder = 'desc'
|
||||
} = options;
|
||||
|
||||
// Build base filter
|
||||
const filter: Record<string, unknown> = {};
|
||||
@ -104,6 +106,10 @@ export class RoomRepository<TRoom extends MeetRoom = MeetRoom> extends BaseRepos
|
||||
filter.roomName = new RegExp(roomName, 'i');
|
||||
}
|
||||
|
||||
if (status) {
|
||||
filter.status = status;
|
||||
}
|
||||
|
||||
// Use base repository's pagination method
|
||||
const result = await this.findMany(filter, {
|
||||
maxItems,
|
||||
|
||||
@ -213,32 +213,18 @@ export class RecordingService {
|
||||
nextPageToken?: string;
|
||||
}> {
|
||||
try {
|
||||
const { maxItems, nextPageToken, roomId, roomName, fields } = filters;
|
||||
|
||||
const response = await this.recordingRepository.find({
|
||||
roomId,
|
||||
roomName,
|
||||
maxItems,
|
||||
nextPageToken
|
||||
});
|
||||
const { fields, ...findOptions } = filters;
|
||||
const response = await this.recordingRepository.find(findOptions);
|
||||
|
||||
// Apply field filtering if specified
|
||||
let recordings = response.recordings;
|
||||
|
||||
if (fields) {
|
||||
recordings = recordings.map((rec: MeetRecordingInfo) =>
|
||||
response.recordings = response.recordings.map((rec: MeetRecordingInfo) =>
|
||||
UtilsHelper.filterObjectFields(rec, fields)
|
||||
) as MeetRecordingInfo[];
|
||||
}
|
||||
|
||||
this.logger.info(`Retrieved ${recordings.length} recordings.`);
|
||||
|
||||
// Return the paginated list of recordings
|
||||
return {
|
||||
recordings,
|
||||
isTruncated: response.isTruncated,
|
||||
nextPageToken: response.nextPageToken
|
||||
};
|
||||
this.logger.info(`Retrieved ${response.recordings.length} recordings.`);
|
||||
return response;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error getting recordings: ${error}`);
|
||||
throw error;
|
||||
|
||||
@ -216,9 +216,7 @@ export class RoomService {
|
||||
nextPageToken?: string;
|
||||
}> {
|
||||
const { fields, ...findOptions } = filters;
|
||||
const response = await this.roomRepository.find({
|
||||
...findOptions
|
||||
});
|
||||
const response = await this.roomRepository.find(findOptions);
|
||||
|
||||
if (fields) {
|
||||
const filteredRooms = response.rooms.map((room: MeetRoom) => UtilsHelper.filterObjectFields(room, fields));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user