Skip to content

Commit

Permalink
fix: save the settings modified by the override rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gauthier-th committed Oct 26, 2024
1 parent 81c1b70 commit fd2b1e4
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions server/entity/MediaRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ export class MediaRequest {
)?.rootFolder;
if (overrideRootFolder) {
rootFolder = overrideRootFolder;
this.rootFolder = rootFolder;
logger.info(
`Request has an override root folder from override rules: ${rootFolder}`,
{
Expand Down Expand Up @@ -834,6 +835,7 @@ export class MediaRequest {
)?.profileId;
if (overrideProfileId) {
qualityProfile = overrideProfileId;
this.profileId = qualityProfile;
logger.info(
`Request has an override quality profile ID from override rules: ${qualityProfile}`,
{
Expand Down Expand Up @@ -864,6 +866,7 @@ export class MediaRequest {
...overrideTags.split(',').map((tag) => Number(tag)),
]),
];
this.tags = tags;
logger.info(`Request has override tags from override rules`, {
label: 'Media Request',
requestId: this.id,
Expand All @@ -873,6 +876,9 @@ export class MediaRequest {
}
}

const requestRepository = getRepository(MediaRequest);
requestRepository.save(this);

if (radarrSettings.tagRequests) {
let userTag = (await radarr.getTags()).find((v) =>
v.label.startsWith(this.requestedBy.id + ' - ')
Expand Down Expand Up @@ -914,7 +920,6 @@ export class MediaRequest {
mediaId: this.media.id,
});

const requestRepository = getRepository(MediaRequest);
this.status = MediaRequestStatus.APPROVED;
await requestRepository.save(this);
return;
Expand Down Expand Up @@ -954,8 +959,6 @@ export class MediaRequest {
await mediaRepository.save(media);
})
.catch(async () => {
const requestRepository = getRepository(MediaRequest);

this.status = MediaRequestStatus.FAILED;
requestRepository.save(this);

Expand Down Expand Up @@ -1055,6 +1058,7 @@ export class MediaRequest {
throw new Error('Media data not found');
}

const requestRepository = getRepository(MediaRequest);
if (
media[this.is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE
) {
Expand All @@ -1064,7 +1068,6 @@ export class MediaRequest {
mediaId: this.media.id,
});

const requestRepository = getRepository(MediaRequest);
this.status = MediaRequestStatus.APPROVED;
await requestRepository.save(this);
return;
Expand All @@ -1079,7 +1082,6 @@ export class MediaRequest {
const tvdbId = series.external_ids.tvdb_id ?? media.tvdbId;

if (!tvdbId) {
const requestRepository = getRepository(MediaRequest);
await mediaRepository.remove(media);
await requestRepository.remove(this);
throw new Error('TVDB ID not found');
Expand Down Expand Up @@ -1183,6 +1185,7 @@ export class MediaRequest {
)?.rootFolder;
if (overrideRootFolder) {
rootFolder = overrideRootFolder;
this.rootFolder = rootFolder;
logger.info(
`Request has an override root folder from override rules: ${rootFolder}`,
{
Expand Down Expand Up @@ -1210,6 +1213,7 @@ export class MediaRequest {
)?.profileId;
if (overrideProfileId) {
qualityProfile = overrideProfileId;
this.profileId = qualityProfile;
logger.info(
`Request has an override quality profile ID from override rules: ${qualityProfile}`,
{
Expand Down Expand Up @@ -1255,6 +1259,7 @@ export class MediaRequest {
...overrideTags.split(',').map((tag) => Number(tag)),
]),
];
this.tags = tags;
logger.info(`Request has override tags from override rules`, {
label: 'Media Request',
requestId: this.id,
Expand Down Expand Up @@ -1296,6 +1301,8 @@ export class MediaRequest {
}
}

requestRepository.save(this);

const sonarrSeriesOptions: AddSeriesOptions = {
profileId: qualityProfile,
languageProfileId: languageProfile,
Expand Down Expand Up @@ -1332,8 +1339,6 @@ export class MediaRequest {
await mediaRepository.save(media);
})
.catch(async () => {
const requestRepository = getRepository(MediaRequest);

this.status = MediaRequestStatus.FAILED;
requestRepository.save(this);

Expand Down

0 comments on commit fd2b1e4

Please sign in to comment.