Skip to content

Commit

Permalink
validated cron checkRssConfigUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
f-w committed Oct 29, 2023
1 parent 4cb643d commit 02e7fd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/api/common/base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class BaseService<T> {
updateDto.updatedBy = req.user;
updateDto.updated = new Date();
}
delete updateDto.id;
return this.model.findByIdAndUpdate(id, updateDto).exec();
}

Expand All @@ -138,6 +139,7 @@ export class BaseService<T> {
req: (Request & { user?: any }) | null,
upsert: boolean = false,
): Promise<T> {
delete updateDto.id;
return this.findOneAndReplace(updateDto, { _id }, req, upsert);
}

Expand All @@ -151,6 +153,7 @@ export class BaseService<T> {
updateDto.updatedBy = req.user;
updateDto.updated = new Date();
}
delete updateDto.id;
const res = await this.model
.findOneAndReplace(filter, updateDto, {
upsert,
Expand Down
25 changes: 14 additions & 11 deletions src/observers/cron-tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class CronTasksService {
items.push(item);
}
});
feedparser.on('end', async function () {
feedparser.on('end', async () => {
const itemKeyField =
rssNtfctnConfigItem.value.rss.itemKeyField || 'guid';
const fieldsToCheckForUpdate = rssNtfctnConfigItem.value.rss
Expand Down Expand Up @@ -400,6 +400,7 @@ export class CronTasksService {
message,
data: newOrUpdatedItem,
httpHost: rssNtfctnConfigItem.value.httpHost,
asyncBroadcastPushNotification: true,
};
const httpHost =
this.appConfigService.get('internalHttpHost') ||
Expand All @@ -416,21 +417,21 @@ export class CronTasksService {
},
};
try {
await fetch(url, options);
const res = await fetch(url, options);
if (res.status >= 400)
throw new HttpException(res.statusText, res.status);
} catch (ex: any) {
this.logger.error(new Error(ex.message));
this.logger.error(ex);
}
}
});
if (!lastSavedRssData) {
return;
}
lastSavedRssData.items = items.concat(retainedOutdatedItems);
lastSavedRssData.lastPoll = ts;
await this.rssService.updateById(
lastSavedRssData.id,
lastSavedRssData,
);
await this.rssService.updateById(lastSavedRssData.id, {
items: items.concat(retainedOutdatedItems),
lastPoll: ts,
});
});
const res = await fetch(rssNtfctnConfigItem.value.rss.url);
if (res.status !== 200) {
Expand Down Expand Up @@ -533,9 +534,11 @@ export class CronTasksService {
},
};
try {
await fetch(url, options);
const res = await fetch(url, options);
if (res.status >= 400)
throw new HttpException(res.statusText, res.status);
} catch (ex: any) {
this.logger.error(new Error(ex.message));
this.logger.error(ex);
}
},
),
Expand Down

0 comments on commit 02e7fd6

Please sign in to comment.