2023-03-12 20:51:45 +01:00
|
|
|
const { DataTypes, Model } = require('sequelize')
|
|
|
|
|
|
|
|
module.exports = (sequelize) => {
|
|
|
|
class LibraryFile extends Model { }
|
|
|
|
|
|
|
|
LibraryFile.init({
|
|
|
|
id: {
|
|
|
|
type: DataTypes.UUID,
|
|
|
|
defaultValue: DataTypes.UUIDV4,
|
|
|
|
primaryKey: true
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
sequelize,
|
2023-03-19 21:19:22 +01:00
|
|
|
modelName: 'libraryFile'
|
2023-03-12 20:51:45 +01:00
|
|
|
})
|
|
|
|
|
2023-03-19 21:19:22 +01:00
|
|
|
const { libraryItem, fileMetadata } = sequelize.models
|
|
|
|
libraryItem.hasMany(LibraryFile)
|
|
|
|
LibraryFile.belongsTo(libraryItem)
|
2023-03-12 20:51:45 +01:00
|
|
|
|
2023-03-19 21:19:22 +01:00
|
|
|
fileMetadata.hasOne(LibraryFile, { foreignKey: 'fileMetadataId' })
|
|
|
|
LibraryFile.belongsTo(fileMetadata, { as: 'fileMetadata', foreignKey: 'fileMetadataId' })
|
2023-03-12 20:51:45 +01:00
|
|
|
|
|
|
|
return LibraryFile
|
|
|
|
}
|