frontend: streamline recording deletion logic and remove unused statusCode from HTTP responses

This commit is contained in:
juancarmore 2025-09-03 19:16:21 +02:00
parent 7295c45d07
commit 8ac17ad5aa
7 changed files with 80 additions and 98 deletions

View File

@ -157,8 +157,8 @@ export class RecordingsComponent implements OnInit {
await this.recordingService.deleteRecording(recording.recordingId);
// Remove from local list
const currentRecordings = this.recordings();
this.recordings.set(currentRecordings.filter((r) => r.recordingId !== recording.recordingId));
this.recordings.set(this.recordings().filter((r) => r.recordingId !== recording.recordingId));
this.notificationService.showSnackbar('Recording deleted successfully');
} catch (error) {
this.log.e('Error deleting recording:', error);
@ -180,38 +180,37 @@ export class RecordingsComponent implements OnInit {
const bulkDeleteCallback = async () => {
try {
const recordingIds = recordings.map((r) => r.recordingId);
const response = await this.recordingService.bulkDeleteRecordings(recordingIds);
const { deleted } = await this.recordingService.bulkDeleteRecordings(recordingIds);
const currentRecordings = this.recordings();
// Remove deleted recordings from the list
this.recordings.set(this.recordings().filter((r) => !deleted.includes(r.recordingId)));
switch (response.statusCode) {
case 204:
// All recordings deleted successfully
this.recordings.set(currentRecordings.filter((r) => !recordingIds.includes(r.recordingId)));
this.notificationService.showSnackbar('All recordings deleted successfully');
break;
case 200:
// Some recordings were deleted, some not
const { deleted = [], notDeleted = [] } = response;
// Remove deleted recordings from the list
this.recordings.set(currentRecordings.filter((r) => !deleted.includes(r.recordingId)));
let msg = '';
if (deleted.length > 0) {
msg += `${deleted.length} recording(s) deleted successfully. `;
}
if (notDeleted.length > 0) {
msg += `${notDeleted.length} recording(s) could not be deleted.`;
}
this.notificationService.showSnackbar(msg.trim());
this.log.w('Some recordings could not be deleted:', notDeleted);
break;
}
} catch (error) {
this.notificationService.showSnackbar('All recordings deleted successfully');
} catch (error: any) {
this.log.e('Error deleting recordings:', error);
this.notificationService.showSnackbar('Failed to delete recordings');
const deleted = error.error?.deleted as string[];
const failed = error.error?.failed as { recordingId: string; error: string }[];
// Some recordings were deleted, some not
if (failed) {
// Remove deleted recordings from the list
if (deleted.length > 0) {
this.recordings.set(this.recordings().filter((r) => !deleted.includes(r.recordingId)));
}
let msg = '';
if (deleted.length > 0) {
msg += `${deleted.length} recording(s) deleted successfully. `;
}
if (failed.length > 0) {
msg += `${failed.length} recording(s) could not be deleted.`;
}
this.notificationService.showSnackbar(msg.trim());
} else {
this.notificationService.showSnackbar('Failed to delete recordings');
}
}
};

View File

@ -298,19 +298,14 @@ export class RoomsComponent implements OnInit {
private async closeRoom(room: MeetRoom) {
try {
const { statusCode, room: updatedRoom } = await this.roomService.updateRoomStatus(
const { message, room: updatedRoom } = await this.roomService.updateRoomStatus(
room.roomId,
MeetRoomStatus.CLOSED
);
// Update room in the list
this.rooms.set(this.rooms().map((r) => (r.roomId === updatedRoom.roomId ? updatedRoom : r)));
if (statusCode === 202) {
this.notificationService.showSnackbar('Room scheduled to be closed when the meeting ends');
} else {
this.notificationService.showSnackbar('Room closed successfully');
}
this.notificationService.showSnackbar(this.removeRoomIdFromMessage(message));
} catch (error) {
this.notificationService.showSnackbar('Failed to close room');
this.log.e('Error closing room:', error);
@ -334,7 +329,7 @@ export class RoomsComponent implements OnInit {
// Check if errorCode exists and is a valid MeetRoomDeletionErrorCode
const errorCode = error.error?.error;
if (errorCode && this.isValidMeetRoomDeletionErrorCode(errorCode)) {
const errorMessage = this.extractGenericMessage(error.error.message);
const errorMessage = this.removeRoomIdFromMessage(error.error.message);
this.showDeletionErrorDialogWithOptions(roomId, errorMessage);
} else {
this.notificationService.showSnackbar('Failed to delete room');
@ -372,7 +367,7 @@ export class RoomsComponent implements OnInit {
this.rooms.set(this.rooms().filter((r) => r.roomId !== roomId));
}
this.notificationService.showSnackbar(this.extractGenericMessage(message));
this.notificationService.showSnackbar(this.removeRoomIdFromMessage(message));
}
private showDeletionErrorDialogWithOptions(roomId: string, errorMessage: string) {
@ -426,7 +421,7 @@ export class RoomsComponent implements OnInit {
const successful = error.error?.successful;
const errorMessage = error.error?.message;
if (failed && successful) {
if (failed) {
this.handleSuccessfulBulkDeletion(successful);
const hasRoomDeletionError = failed.some((result) =>
@ -564,15 +559,13 @@ export class RoomsComponent implements OnInit {
* @param message - The original message from the API response
* @returns The message without the specific room ID
*/
private extractGenericMessage(message: string): string {
// Pattern to match room IDs in single quotes: 'room-id'
private removeRoomIdFromMessage(message: string): string {
// Pattern to match room ID in single quotes: 'room-id'
const roomIdPattern = /'[^']+'/g;
// Remove room ID
let genericMessage = message.replace(roomIdPattern, '');
let filteredMessage = message.replace(roomIdPattern, '');
// Clean up any double spaces that might result from the replacement
genericMessage = genericMessage.replace(/\s+/g, ' ').trim();
return genericMessage;
filteredMessage = filteredMessage.replace(/\s+/g, ' ').trim();
return filteredMessage;
}
}

View File

@ -169,8 +169,8 @@ export class RoomRecordingsComponent implements OnInit {
await this.recordingService.deleteRecording(recording.recordingId);
// Remove from local list
const currentRecordings = this.recordings();
this.recordings.set(currentRecordings.filter((r) => r.recordingId !== recording.recordingId));
this.recordings.set(this.recordings().filter((r) => r.recordingId !== recording.recordingId));
this.notificationService.showSnackbar('Recording deleted successfully');
} catch (error) {
this.log.e('Error deleting recording:', error);
@ -192,38 +192,37 @@ export class RoomRecordingsComponent implements OnInit {
const bulkDeleteCallback = async () => {
try {
const recordingIds = recordings.map((r) => r.recordingId);
const response = await this.recordingService.bulkDeleteRecordings(recordingIds);
const { deleted } = await this.recordingService.bulkDeleteRecordings(recordingIds);
const currentRecordings = this.recordings();
// Remove deleted recordings from the list
this.recordings.set(this.recordings().filter((r) => !deleted.includes(r.recordingId)));
switch (response.statusCode) {
case 204:
// All recordings deleted successfully
this.recordings.set(currentRecordings.filter((r) => !recordingIds.includes(r.recordingId)));
this.notificationService.showSnackbar('All recordings deleted successfully');
break;
case 200:
// Some recordings were deleted, some not
const { deleted = [], notDeleted = [] } = response;
// Remove deleted recordings from the list
this.recordings.set(currentRecordings.filter((r) => !deleted.includes(r.recordingId)));
let msg = '';
if (deleted.length > 0) {
msg += `${deleted.length} recording(s) deleted successfully. `;
}
if (notDeleted.length > 0) {
msg += `${notDeleted.length} recording(s) could not be deleted.`;
}
this.notificationService.showSnackbar(msg.trim());
this.log.w('Some recordings could not be deleted:', notDeleted);
break;
}
} catch (error) {
this.notificationService.showSnackbar('All recordings deleted successfully');
} catch (error: any) {
this.log.e('Error deleting recordings:', error);
this.notificationService.showSnackbar('Failed to delete recordings');
const deleted = error.error?.deleted as string[];
const failed = error.error?.failed as { recordingId: string; error: string }[];
// Some recordings were deleted, some not
if (failed) {
// Remove deleted recordings from the list
if (deleted.length > 0) {
this.recordings.set(this.recordings().filter((r) => !deleted.includes(r.recordingId)));
}
let msg = '';
if (deleted.length > 0) {
msg += `${deleted.length} recording(s) deleted successfully. `;
}
if (failed.length > 0) {
msg += `${failed.length} recording(s) could not be deleted.`;
}
this.notificationService.showSnackbar(msg.trim());
} else {
this.notificationService.showSnackbar('Failed to delete recordings');
}
}
};

View File

@ -24,14 +24,8 @@ export class HttpService {
}
async putRequest<T>(path: string, body: any = {}, headers?: Record<string, string>): Promise<T> {
const options = {
observe: 'response' as const,
...(headers ? { headers: new HttpHeaders(headers) } : {})
};
return lastValueFrom(this.http.put<T>(path, body, options)).then((response) => ({
...(response.body as T),
statusCode: response.status
}));
const options = headers ? { headers: new HttpHeaders(headers) } : {};
return lastValueFrom(this.http.put<T>(path, body, options));
}
async patchRequest<T>(path: string, body: any = {}, headers?: Record<string, string>): Promise<T> {
@ -40,13 +34,7 @@ export class HttpService {
}
async deleteRequest<T>(path: string, headers?: Record<string, string>): Promise<T> {
const options = {
observe: 'response' as const,
...(headers ? { headers: new HttpHeaders(headers) } : {})
};
return lastValueFrom(this.http.delete<T>(path, options)).then((response) => ({
...(response.body as T),
statusCode: response.status
}));
const options = headers ? { headers: new HttpHeaders(headers) } : {};
return lastValueFrom(this.http.delete<T>(path, options));
}
}

View File

@ -41,7 +41,7 @@ export class MeetingService {
const path = `${this.MEETINGS_API}/${roomId}/participants/${participantIdentity}`;
const headers = this.participantService.getParticipantRoleHeader();
await this.httpService.deleteRequest(path, headers);
this.log.d(`Participant '${participantIdentity}' kicked from room ${roomId}`);
this.log.d(`Participant '${participantIdentity}' kicked from room '${roomId}'`);
}
/**

View File

@ -217,7 +217,10 @@ export class RecordingService {
* @param recordingIds - An array of recording IDs to delete
* @return A promise that resolves to the deletion response
*/
async bulkDeleteRecordings(recordingIds: string[]): Promise<any> {
async bulkDeleteRecordings(recordingIds: string[]): Promise<{
message: string;
deleted: string[];
}> {
if (recordingIds.length === 0) {
throw new Error('No recording IDs provided for bulk deletion');
}

View File

@ -120,7 +120,7 @@ export class RoomService {
* @param status - The new status to be set
* @return A promise that resolves to an object containing the updated room and a status code
*/
async updateRoomStatus(roomId: string, status: MeetRoomStatus): Promise<{ statusCode: number; room: MeetRoom }> {
async updateRoomStatus(roomId: string, status: MeetRoomStatus): Promise<{ message: string; room: MeetRoom }> {
const path = `${this.ROOMS_API}/${roomId}/status`;
return this.httpService.putRequest(path, { status });
}