From b04e7461274a619a0faa64de8dbaa3bbd6e68767 Mon Sep 17 00:00:00 2001 From: Omar Reda Date: Sat, 2 May 2026 21:30:05 +0300 Subject: [PATCH] fix(admin): fix toggle hidden status internal server error --- src/admin/admin.service.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/admin/admin.service.ts b/src/admin/admin.service.ts index 1a9bc3f2..b2da0423 100644 --- a/src/admin/admin.service.ts +++ b/src/admin/admin.service.ts @@ -291,27 +291,25 @@ export class AdminService { } async toggleTrackVisibility(trackId: string, hidden: boolean) { - const track = await this.trackRepository.findById(trackId); + const track = await this.trackRepository.findByIdWithRelations(trackId); if (!track) { throw new NotFoundException('Track not found'); } - // 1. Update the DB via your new repo method await this.trackRepository.updateHiddenStatus(trackId, hidden); - // 2. Sync Meilisearch - if (hidden === true) { - // Even if the track is PUBLIC, if it's hidden, it's gone from search + track.hidden = hidden; + + if (hidden) { await deleteDocument(`track_${trackId}`); + } else if ( + track.visibility === TrackVisibility.PUBLIC && + track.trackStatus === TrackStatus.FINISHED + ) { + await updateDocument(mapTrack(track)); } else { - // Only add back to search if the track was originally PUBLIC - // If it was PRIVATE, it shouldn't be in the index anyway - // eslint-disable-next-line no-lonely-if - if (track.visibility === TrackVisibility.PUBLIC) { - // We pass the track object with the updated hidden status - await updateDocument(mapTrack({ ...track, hidden: false })); - } + await deleteDocument(`track_${trackId}`); } return {