Remove series search api endpoint, update authors and series to load from db

This commit is contained in:
advplyr 2023-09-03 10:49:02 -05:00
parent 7567e91878
commit 9123dcb365
10 changed files with 79 additions and 53 deletions

View file

@ -1,4 +1,4 @@
const { DataTypes, Model } = require('sequelize')
const { DataTypes, Model, literal } = require('sequelize')
const oldAuthor = require('../objects/entities/Author')
@ -86,7 +86,7 @@ class Author extends Model {
/**
* Get oldAuthor by id
* @param {string} authorId
* @returns {oldAuthor}
* @returns {Promise<oldAuthor>}
*/
static async getOldById(authorId) {
const author = await this.findByPk(authorId)
@ -103,6 +103,26 @@ class Author extends Model {
return (await this.count({ where: { id: authorId } })) > 0
}
/**
* Get old author by name and libraryId. name case insensitive
* TODO: Look for authors ignoring punctuation
*
* @param {string} authorName
* @param {string} libraryId
* @returns {Promise<oldAuthor>}
*/
static async getOldByNameAndLibrary(authorName, libraryId) {
const author = (await this.findOne({
where: [
literal(`name = '${authorName}' COLLATE NOCASE`),
{
libraryId
}
]
}))?.getOldAuthor()
return author
}
/**
* Initialize model
* @param {import('../Database').sequelize} sequelize

View file

@ -1,4 +1,4 @@
const { DataTypes, Model } = require('sequelize')
const { DataTypes, Model, literal } = require('sequelize')
const oldSeries = require('../objects/entities/Series')
@ -75,6 +75,17 @@ class Series extends Model {
})
}
/**
* Get oldSeries by id
* @param {string} seriesId
* @returns {Promise<oldSeries>}
*/
static async getOldById(seriesId) {
const series = await this.findByPk(seriesId)
if (!series) return null
return series.getOldSeries()
}
/**
* Check if series exists
* @param {string} seriesId
@ -84,6 +95,25 @@ class Series extends Model {
return (await this.count({ where: { id: seriesId } })) > 0
}
/**
* Get old series by name and libraryId. name case insensitive
*
* @param {string} seriesName
* @param {string} libraryId
* @returns {Promise<oldSeries>}
*/
static async getOldByNameAndLibrary(seriesName, libraryId) {
const series = (await this.findOne({
where: [
literal(`name = '${seriesName}' COLLATE NOCASE`),
{
libraryId
}
]
}))?.getOldSeries()
return series
}
/**
* Initialize model
* @param {import('../Database').sequelize} sequelize