mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const { DataTypes, Model } = require('sequelize')
 | 
						|
 | 
						|
class LibraryFolder extends Model {
 | 
						|
  constructor(values, options) {
 | 
						|
    super(values, options)
 | 
						|
 | 
						|
    /** @type {UUIDV4} */
 | 
						|
    this.id
 | 
						|
    /** @type {string} */
 | 
						|
    this.path
 | 
						|
    /** @type {UUIDV4} */
 | 
						|
    this.libraryId
 | 
						|
    /** @type {Date} */
 | 
						|
    this.createdAt
 | 
						|
    /** @type {Date} */
 | 
						|
    this.updatedAt
 | 
						|
  }
 | 
						|
 | 
						|
  /**
 | 
						|
   * Initialize model
 | 
						|
   * @param {import('../Database').sequelize} sequelize
 | 
						|
   */
 | 
						|
  static init(sequelize) {
 | 
						|
    super.init(
 | 
						|
      {
 | 
						|
        id: {
 | 
						|
          type: DataTypes.UUID,
 | 
						|
          defaultValue: DataTypes.UUIDV4,
 | 
						|
          primaryKey: true
 | 
						|
        },
 | 
						|
        path: DataTypes.STRING
 | 
						|
      },
 | 
						|
      {
 | 
						|
        sequelize,
 | 
						|
        modelName: 'libraryFolder'
 | 
						|
      }
 | 
						|
    )
 | 
						|
 | 
						|
    const { library } = sequelize.models
 | 
						|
    library.hasMany(LibraryFolder, {
 | 
						|
      onDelete: 'CASCADE'
 | 
						|
    })
 | 
						|
    LibraryFolder.belongsTo(library)
 | 
						|
  }
 | 
						|
 | 
						|
  /**
 | 
						|
   * TODO: Update to use new model
 | 
						|
   */
 | 
						|
  toOldJSON() {
 | 
						|
    return {
 | 
						|
      id: this.id,
 | 
						|
      fullPath: this.path,
 | 
						|
      libraryId: this.libraryId,
 | 
						|
      addedAt: this.createdAt.valueOf()
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
module.exports = LibraryFolder
 |