2023-07-05 01:14:44 +02:00
|
|
|
const { DataTypes, Model } = require('sequelize')
|
|
|
|
|
|
|
|
module.exports = (sequelize) => {
|
2023-07-22 21:25:20 +02:00
|
|
|
class LibraryFolder extends Model {
|
|
|
|
/**
|
|
|
|
* Gets all library folder path strings
|
|
|
|
* @returns {Promise<string[]>} array of library folder paths
|
|
|
|
*/
|
|
|
|
static async getAllLibraryFolderPaths() {
|
|
|
|
const libraryFolders = await this.findAll({
|
|
|
|
attributes: ['path']
|
|
|
|
})
|
|
|
|
return libraryFolders.map(l => l.path)
|
|
|
|
}
|
|
|
|
}
|
2023-07-05 01:14:44 +02:00
|
|
|
|
|
|
|
LibraryFolder.init({
|
|
|
|
id: {
|
|
|
|
type: DataTypes.UUID,
|
|
|
|
defaultValue: DataTypes.UUIDV4,
|
|
|
|
primaryKey: true
|
|
|
|
},
|
|
|
|
path: DataTypes.STRING
|
|
|
|
}, {
|
|
|
|
sequelize,
|
|
|
|
modelName: 'libraryFolder'
|
|
|
|
})
|
|
|
|
|
|
|
|
const { library } = sequelize.models
|
2023-07-09 18:39:15 +02:00
|
|
|
library.hasMany(LibraryFolder, {
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
2023-07-05 01:14:44 +02:00
|
|
|
LibraryFolder.belongsTo(library)
|
|
|
|
|
|
|
|
return LibraryFolder
|
|
|
|
}
|