Update recent-episodes API route to load from db

This commit is contained in:
advplyr 2023-08-19 14:49:06 -05:00
parent f21d69339f
commit 8d451217a3
6 changed files with 88 additions and 31 deletions

View file

@ -1,4 +1,5 @@
const { DataTypes, Model } = require('sequelize')
const oldPodcastEpisode = require('../objects/entities/PodcastEpisode')
class PodcastEpisode extends Model {
constructor(values, options) {
@ -44,6 +45,10 @@ class PodcastEpisode extends Model {
this.updatedAt
}
/**
* @param {string} libraryItemId
* @returns {oldPodcastEpisode}
*/
getOldPodcastEpisode(libraryItemId = null) {
let enclosure = null
if (this.enclosureURL) {
@ -53,7 +58,7 @@ class PodcastEpisode extends Model {
length: this.enclosureSize !== null ? String(this.enclosureSize) : null
}
}
return {
return new oldPodcastEpisode({
libraryItemId: libraryItemId || null,
podcastId: this.podcastId,
id: this.id,
@ -72,7 +77,7 @@ class PodcastEpisode extends Model {
publishedAt: this.publishedAt?.valueOf() || null,
addedAt: this.createdAt.valueOf(),
updatedAt: this.updatedAt.valueOf()
}
})
}
static createFromOld(oldEpisode) {