mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
feat(api): add issue counts endpoint (#2713)
This commit is contained in:

committed by
GitHub

parent
29be659512
commit
e4039d09c0
@@ -5562,6 +5562,36 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Issue'
|
$ref: '#/components/schemas/Issue'
|
||||||
|
|
||||||
|
/issue/count:
|
||||||
|
get:
|
||||||
|
summary: Gets issue counts
|
||||||
|
description: |
|
||||||
|
Returns the number of open and closed issues, as well as the number of issues of each type.
|
||||||
|
tags:
|
||||||
|
- issue
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Issue counts returned
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
total:
|
||||||
|
type: number
|
||||||
|
video:
|
||||||
|
type: number
|
||||||
|
audio:
|
||||||
|
type: number
|
||||||
|
subtitles:
|
||||||
|
type: number
|
||||||
|
others:
|
||||||
|
type: number
|
||||||
|
open:
|
||||||
|
type: number
|
||||||
|
closed:
|
||||||
|
type: number
|
||||||
/issue/{issueId}:
|
/issue/{issueId}:
|
||||||
get:
|
get:
|
||||||
summary: Get issue
|
summary: Get issue
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import { getRepository } from 'typeorm';
|
import { getRepository } from 'typeorm';
|
||||||
import { IssueStatus } from '../constants/issue';
|
import { IssueStatus, IssueType } from '../constants/issue';
|
||||||
import Issue from '../entity/Issue';
|
import Issue from '../entity/Issue';
|
||||||
import IssueComment from '../entity/IssueComment';
|
import IssueComment from '../entity/IssueComment';
|
||||||
import Media from '../entity/Media';
|
import Media from '../entity/Media';
|
||||||
@@ -146,6 +146,68 @@ issueRoutes.post<
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
issueRoutes.get('/count', async (req, res, next) => {
|
||||||
|
const issueRepository = getRepository(Issue);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const query = issueRepository.createQueryBuilder('issue');
|
||||||
|
|
||||||
|
const totalCount = await query.getCount();
|
||||||
|
|
||||||
|
const videoCount = await query
|
||||||
|
.where('issue.issueType = :issueType', {
|
||||||
|
issueType: IssueType.VIDEO,
|
||||||
|
})
|
||||||
|
.getCount();
|
||||||
|
|
||||||
|
const audioCount = await query
|
||||||
|
.where('issue.issueType = :issueType', {
|
||||||
|
issueType: IssueType.AUDIO,
|
||||||
|
})
|
||||||
|
.getCount();
|
||||||
|
|
||||||
|
const subtitlesCount = await query
|
||||||
|
.where('issue.issueType = :issueType', {
|
||||||
|
issueType: IssueType.SUBTITLES,
|
||||||
|
})
|
||||||
|
.getCount();
|
||||||
|
|
||||||
|
const othersCount = await query
|
||||||
|
.where('issue.issueType = :issueType', {
|
||||||
|
issueType: IssueType.OTHER,
|
||||||
|
})
|
||||||
|
.getCount();
|
||||||
|
|
||||||
|
const openCount = await query
|
||||||
|
.where('issue.status = :issueStatus', {
|
||||||
|
issueStatus: IssueStatus.OPEN,
|
||||||
|
})
|
||||||
|
.getCount();
|
||||||
|
|
||||||
|
const closedCount = await query
|
||||||
|
.where('issue.status = :issueStatus', {
|
||||||
|
issueStatus: IssueStatus.RESOLVED,
|
||||||
|
})
|
||||||
|
.getCount();
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
total: totalCount,
|
||||||
|
video: videoCount,
|
||||||
|
audio: audioCount,
|
||||||
|
subtitles: subtitlesCount,
|
||||||
|
others: othersCount,
|
||||||
|
open: openCount,
|
||||||
|
closed: closedCount,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
logger.debug('Something went wrong retrieving issue counts.', {
|
||||||
|
label: 'API',
|
||||||
|
errorMessage: e.message,
|
||||||
|
});
|
||||||
|
next({ status: 500, message: 'Unable to retrieve issue counts.' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
issueRoutes.get<{ issueId: string }>(
|
issueRoutes.get<{ issueId: string }>(
|
||||||
'/:issueId',
|
'/:issueId',
|
||||||
isAuthenticated(
|
isAuthenticated(
|
||||||
|
Reference in New Issue
Block a user