Skip to content

Commit

Permalink
fix(highlights): fix error if all videos are expired
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Jan 24, 2022
1 parent 57704d6 commit 5772b31
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/systems/highlights.ts
Expand Up @@ -50,22 +50,29 @@ class Highlights extends System {
});
});
adminEndpoint(this.nsp, 'generic::getAll', async (cb) => {
try {
(async function getAll(callback): Promise<void> {
const highlightsToCheck = await getRepository(Highlight).find({ order: { createdAt: 'DESC' }, where: { expired: false } });
try {
const clientBot = await client('bot');
const availableVideos = await clientBot.videos.getVideosByIds(highlightsToCheck.map(o => o.videoId));

const clientBot = await client('bot');
const availableVideos = await clientBot.videos.getVideosByIds(highlightsToCheck.map(o => o.videoId));

for (const highlight of highlightsToCheck) {
if (!availableVideos.find(o => o.id === highlight.videoId)) {
await getRepository(Highlight).update(highlight.id, { expired: true });
for (const highlight of highlightsToCheck) {
if (!availableVideos.find(o => o.id === highlight.videoId)) {
await getRepository(Highlight).update(highlight.id, { expired: true });
}
}
const highlights = await getRepository(Highlight).find({ order: { createdAt: 'DESC' } });
callback(null, highlights, availableVideos);
} catch (err: any) {
if (err._statusCode === 404) {
for (const highlight of highlightsToCheck) {
await getRepository(Highlight).update(highlight.id, { expired: true });
}
return getAll(callback);
}
callback(err.stack);
}
const highlights = await getRepository(Highlight).find({ order: { createdAt: 'DESC' } });
cb(null, highlights, availableVideos);
} catch (err: any) {
cb(err.stack);
}
})(cb);
});
adminEndpoint(this.nsp, 'generic::deleteById', async (id, cb) => {
try {
Expand Down

0 comments on commit 5772b31

Please sign in to comment.