Updates to use new Library model

This commit is contained in:
advplyr 2024-08-23 16:59:51 -05:00
parent 8774e6be71
commit 38edcdca4b
6 changed files with 114 additions and 57 deletions

View file

@ -43,6 +43,8 @@ class Library extends Model {
this.createdAt
/** @type {Date} */
this.updatedAt
/** @type {import('./LibraryFolder')[]|undefined} */
this.libraryFolders
}
/**
@ -74,6 +76,28 @@ class Library extends Model {
}
}
/**
*
* @returns {Promise<Library[]>}
*/
static getAllWithFolders() {
return this.findAll({
include: this.sequelize.models.libraryFolder,
order: [['displayOrder', 'ASC']]
})
}
/**
*
* @param {string} libraryId
* @returns {Promise<Library>}
*/
static findByIdWithFolders(libraryId) {
return this.findByPk(libraryId, {
include: this.sequelize.models.libraryFolder
})
}
/**
* Get all old libraries
* @returns {Promise<oldLibrary[]>}
@ -121,7 +145,7 @@ class Library extends Model {
/**
* Update library and library folders
* @param {object} oldLibrary
* @returns
* @returns {Promise<Library|null>}
*/
static async updateFromOld(oldLibrary) {
const existingLibrary = await this.findByPk(oldLibrary.id, {