Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions server/entity/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export class User {
requestedBy: {
id: this.id,
},
createdAt: AfterDate(movieDate),
...(movieQuotaDays ? { createdAt: AfterDate(movieDate) } : {}),
type: MediaType.MOVIE,
status: Not(MediaRequestStatus.DECLINED),
},
Expand All @@ -314,24 +314,28 @@ export class User {
tvDate.setDate(tvDate.getDate() - tvQuotaDays);
}
const tvQuotaStartDate = tvDate.toJSON();
const tvQuotaUsedQuery = requestRepository
.createQueryBuilder('request')
.leftJoin('request.requestedBy', 'requestedBy')
.where('request.type = :requestType', {
requestType: MediaType.TV,
})
.andWhere('requestedBy.id = :userId', {
userId: this.id,
})
.andWhere('request.status != :declinedStatus', {
declinedStatus: MediaRequestStatus.DECLINED,
});

if (tvQuotaDays) {
tvQuotaUsedQuery.andWhere('request.createdAt > :date', {
date: tvQuotaStartDate,
});
}

const tvQuotaUsed = tvQuotaLimit
? (
await requestRepository
.createQueryBuilder('request')
.leftJoin('request.seasons', 'seasons')
.leftJoin('request.requestedBy', 'requestedBy')
.where('request.type = :requestType', {
requestType: MediaType.TV,
})
.andWhere('requestedBy.id = :userId', {
userId: this.id,
})
.andWhere('request.createdAt > :date', {
date: tvQuotaStartDate,
})
.andWhere('request.status != :declinedStatus', {
declinedStatus: MediaRequestStatus.DECLINED,
})
await tvQuotaUsedQuery
.addSelect((subQuery) => {
return subQuery
.select('COUNT(season.id)', 'seasonCount')
Expand All @@ -351,10 +355,9 @@ export class User {
remaining: movieQuotaLimit
? Math.max(0, movieQuotaLimit - movieQuotaUsed)
: undefined,
restricted:
restricted: !!(
movieQuotaLimit && movieQuotaLimit - movieQuotaUsed <= 0
? true
: false,
),
},
tv: {
days: tvQuotaDays,
Expand All @@ -363,8 +366,7 @@ export class User {
remaining: tvQuotaLimit
? Math.max(0, tvQuotaLimit - tvQuotaUsed)
: undefined,
restricted:
tvQuotaLimit && tvQuotaLimit - tvQuotaUsed <= 0 ? true : false,
restricted: !!(tvQuotaLimit && tvQuotaLimit - tvQuotaUsed <= 0),
},
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/QuotaSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ const QuotaSelector = ({
onChange={(e) => setQuotaDays(Number(e.target.value))}
disabled={isDisabled}
>
<option value="0">
{intl.formatMessage(messages.unlimited)}
</option>
{[...Array(100)].map((_item, i) => (
<option value={i + 1} key={`${mediaType}-days-${i + 1}`}>
{i + 1}
Expand Down
4 changes: 2 additions & 2 deletions src/components/RequestModal/QuotaDisplay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const messages = defineMessages('components.RequestModal.QuotaDisplay', {
movielimit: '{limit, plural, one {movie} other {movies}}',
seasonlimit: '{limit, plural, one {season} other {seasons}}',
allowedRequests:
'You are allowed to request <strong>{limit}</strong> {type} every <strong>{days}</strong> days.',
'You are allowed to request <strong>{limit}</strong> {type}{days, plural, =0 {} one { every day} other { every <strong>{days}</strong> days}}.',
allowedRequestsUser:
'This user is allowed to request <strong>{limit}</strong> {type} every <strong>{days}</strong> days.',
'This user is allowed to request <strong>{limit}</strong> {type}{days, plural, =0 {} one { every day} other { every <strong>{days}</strong> days}}.',
quotaLink:
'You can view a summary of your request limits on your <ProfileLink>profile page</ProfileLink>.',
quotaLinkUser:
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@
"components.RequestModal.AdvancedRequester.rootfolder": "Root Folder",
"components.RequestModal.AdvancedRequester.selecttags": "Select tags",
"components.RequestModal.AdvancedRequester.tags": "Tags",
"components.RequestModal.QuotaDisplay.allowedRequests": "You are allowed to request <strong>{limit}</strong> {type} every <strong>{days}</strong> days.",
"components.RequestModal.QuotaDisplay.allowedRequestsUser": "This user is allowed to request <strong>{limit}</strong> {type} every <strong>{days}</strong> days.",
"components.RequestModal.QuotaDisplay.allowedRequests": "You are allowed to request <strong>{limit}</strong> {type}{days, plural, =0 {} one { every day} other { every <strong>{days}</strong> days}}.",
"components.RequestModal.QuotaDisplay.allowedRequestsUser": "This user is allowed to request <strong>{limit}</strong> {type}{days, plural, =0 {} one { every day} other { every <strong>{days}</strong> days}}.",
"components.RequestModal.QuotaDisplay.movie": "movie",
"components.RequestModal.QuotaDisplay.movielimit": "{limit, plural, one {movie} other {movies}}",
"components.RequestModal.QuotaDisplay.notenoughseasonrequests": "Not enough season requests remaining",
Expand Down
Loading