Skip to content

Commit

Permalink
Update:Remove oldSeries model
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Sep 1, 2024
1 parent b6a86d1 commit 9f60017
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 123 deletions.
5 changes: 0 additions & 5 deletions server/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,6 @@ class Database {
await this.models.feed.removeById(feedId)
}

updateSeries(oldSeries) {
if (!this.sequelize) return false
return this.models.series.updateFromOld(oldSeries)
}

async createBulkBookAuthors(bookAuthors) {
if (!this.sequelize) return false
await this.models.bookAuthor.bulkCreate(bookAuthors)
Expand Down
23 changes: 16 additions & 7 deletions server/controllers/SeriesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,28 @@ class SeriesController {
}

/**
* TODO: Update to use new model
* TODO: Currently unused in the client, should check for duplicate name
*
* @param {SeriesControllerRequest} req
* @param {Response} res
*/
async update(req, res) {
const oldSeries = req.series.getOldSeries()
const hasUpdated = oldSeries.update(req.body)
if (hasUpdated) {
await Database.updateSeries(oldSeries)
SocketAuthority.emitter('series_updated', oldSeries.toJSON())
const keysToUpdate = ['name', 'description']
const payload = {}
for (const key of keysToUpdate) {
if (req.body[key] !== undefined && typeof req.body[key] === 'string') {
payload[key] = req.body[key]
}
}
if (!Object.keys(payload).length) {
return res.status(400).send('No valid fields to update')
}
req.series.set(payload)
if (req.series.changed()) {
await req.series.save()
SocketAuthority.emitter('series_updated', req.series.toOldJSON())
}
res.json(oldSeries.toJSON())
res.json(req.series.toOldJSON())
}

/**
Expand Down
31 changes: 0 additions & 31 deletions server/models/Series.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { DataTypes, Model, where, fn, col } = require('sequelize')

const oldSeries = require('../objects/entities/Series')
const { getTitlePrefixAtEnd } = require('../utils/index')

class Series extends Model {
Expand All @@ -23,36 +22,6 @@ class Series extends Model {
this.updatedAt
}

getOldSeries() {
return new oldSeries({
id: this.id,
name: this.name,
description: this.description,
libraryId: this.libraryId,
addedAt: this.createdAt.valueOf(),
updatedAt: this.updatedAt.valueOf()
})
}

static updateFromOld(oldSeries) {
const series = this.getFromOld(oldSeries)
return this.update(series, {
where: {
id: series.id
}
})
}

static getFromOld(oldSeries) {
return {
id: oldSeries.id,
name: oldSeries.name,
nameIgnorePrefix: oldSeries.nameIgnorePrefix,
description: oldSeries.description,
libraryId: oldSeries.libraryId
}
}

/**
* Check if series exists
* @param {string} seriesId
Expand Down
79 changes: 0 additions & 79 deletions server/objects/entities/Series.js

This file was deleted.

2 changes: 1 addition & 1 deletion server/utils/queries/libraryFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ module.exports = {
* @param {import('../../models/User')} user
* @param {string[]} include
* @param {number} limit
* @returns {{ series:import('../../objects/entities/Series')[], count:number}}
* @returns {{ series:any[], count:number}}
*/
async getSeriesMostRecentlyAdded(library, user, include, limit) {
if (!library.isBook) return { series: [], count: 0 }
Expand Down

0 comments on commit 9f60017

Please sign in to comment.