|
|
@ -444,6 +444,20 @@ requestRoutes.get('/count', async (_req, res, next) => {
|
|
|
|
.createQueryBuilder('request')
|
|
|
|
.createQueryBuilder('request')
|
|
|
|
.leftJoinAndSelect('request.media', 'media');
|
|
|
|
.leftJoinAndSelect('request.media', 'media');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const totalCount = await query.getCount();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const movieCount = await query
|
|
|
|
|
|
|
|
.where('request.type = :requestType', {
|
|
|
|
|
|
|
|
requestType: MediaType.MOVIE,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.getCount();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tvCount = await query
|
|
|
|
|
|
|
|
.where('request.type = :requestType', {
|
|
|
|
|
|
|
|
requestType: MediaType.TV,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.getCount();
|
|
|
|
|
|
|
|
|
|
|
|
const pendingCount = await query
|
|
|
|
const pendingCount = await query
|
|
|
|
.where('request.status = :requestStatus', {
|
|
|
|
.where('request.status = :requestStatus', {
|
|
|
|
requestStatus: MediaRequestStatus.PENDING,
|
|
|
|
requestStatus: MediaRequestStatus.PENDING,
|
|
|
@ -456,12 +470,18 @@ requestRoutes.get('/count', async (_req, res, next) => {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.getCount();
|
|
|
|
.getCount();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const declinedCount = await query
|
|
|
|
|
|
|
|
.where('request.status = :requestStatus', {
|
|
|
|
|
|
|
|
requestStatus: MediaRequestStatus.DECLINED,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.getCount();
|
|
|
|
|
|
|
|
|
|
|
|
const processingCount = await query
|
|
|
|
const processingCount = await query
|
|
|
|
.where('request.status = :requestStatus', {
|
|
|
|
.where('request.status = :requestStatus', {
|
|
|
|
requestStatus: MediaRequestStatus.APPROVED,
|
|
|
|
requestStatus: MediaRequestStatus.APPROVED,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.andWhere(
|
|
|
|
.andWhere(
|
|
|
|
'(request.is4k = false AND media.status != :availableStatus) OR (request.is4k = true AND media.status4k != :availableStatus)',
|
|
|
|
'((request.is4k = false AND media.status != :availableStatus) OR (request.is4k = true AND media.status4k != :availableStatus))',
|
|
|
|
{
|
|
|
|
{
|
|
|
|
availableStatus: MediaStatus.AVAILABLE,
|
|
|
|
availableStatus: MediaStatus.AVAILABLE,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -473,7 +493,7 @@ requestRoutes.get('/count', async (_req, res, next) => {
|
|
|
|
requestStatus: MediaRequestStatus.APPROVED,
|
|
|
|
requestStatus: MediaRequestStatus.APPROVED,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.andWhere(
|
|
|
|
.andWhere(
|
|
|
|
'(request.is4k = false AND media.status = :availableStatus) OR (request.is4k = true AND media.status4k = :availableStatus)',
|
|
|
|
'((request.is4k = false AND media.status = :availableStatus) OR (request.is4k = true AND media.status4k = :availableStatus))',
|
|
|
|
{
|
|
|
|
{
|
|
|
|
availableStatus: MediaStatus.AVAILABLE,
|
|
|
|
availableStatus: MediaStatus.AVAILABLE,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -481,13 +501,21 @@ requestRoutes.get('/count', async (_req, res, next) => {
|
|
|
|
.getCount();
|
|
|
|
.getCount();
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
total: totalCount,
|
|
|
|
|
|
|
|
movie: movieCount,
|
|
|
|
|
|
|
|
tv: tvCount,
|
|
|
|
pending: pendingCount,
|
|
|
|
pending: pendingCount,
|
|
|
|
approved: approvedCount,
|
|
|
|
approved: approvedCount,
|
|
|
|
|
|
|
|
declined: declinedCount,
|
|
|
|
processing: processingCount,
|
|
|
|
processing: processingCount,
|
|
|
|
available: availableCount,
|
|
|
|
available: availableCount,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
next({ status: 500, message: e.message });
|
|
|
|
logger.error('Something went wrong retrieving request counts', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
next({ status: 500, message: 'Unable to retrieve request counts.' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|