2023-03-12 20:51:45 +01:00
|
|
|
const { DataTypes, Model } = require('sequelize')
|
|
|
|
|
|
|
|
module.exports = (sequelize) => {
|
|
|
|
class Book extends Model { }
|
|
|
|
|
|
|
|
Book.init({
|
|
|
|
id: {
|
|
|
|
type: DataTypes.UUID,
|
|
|
|
defaultValue: DataTypes.UUIDV4,
|
|
|
|
primaryKey: true
|
|
|
|
},
|
|
|
|
title: DataTypes.STRING,
|
|
|
|
subtitle: DataTypes.STRING,
|
|
|
|
publishedYear: DataTypes.STRING,
|
|
|
|
publishedDate: DataTypes.STRING,
|
|
|
|
publisher: DataTypes.STRING,
|
|
|
|
description: DataTypes.TEXT,
|
|
|
|
isbn: DataTypes.STRING,
|
|
|
|
asin: DataTypes.STRING,
|
|
|
|
language: DataTypes.STRING,
|
|
|
|
explicit: DataTypes.BOOLEAN,
|
|
|
|
lastCoverSearchQuery: DataTypes.STRING,
|
|
|
|
lastCoverSearch: DataTypes.DATE
|
|
|
|
}, {
|
|
|
|
sequelize,
|
2023-03-19 21:19:22 +01:00
|
|
|
modelName: 'book'
|
2023-03-12 20:51:45 +01:00
|
|
|
})
|
|
|
|
|
2023-03-19 21:19:22 +01:00
|
|
|
const { fileMetadata, eBookFile } = sequelize.models
|
2023-03-12 20:51:45 +01:00
|
|
|
|
2023-03-19 21:19:22 +01:00
|
|
|
fileMetadata.hasOne(Book, { foreignKey: 'imageFileId' })
|
|
|
|
Book.belongsTo(fileMetadata, { as: 'imageFile', foreignKey: 'imageFileId' }) // Ref: https://sequelize.org/docs/v6/core-concepts/assocs/#defining-an-alias
|
2023-03-12 20:51:45 +01:00
|
|
|
|
2023-03-19 21:19:22 +01:00
|
|
|
eBookFile.hasOne(Book)
|
|
|
|
Book.belongsTo(eBookFile)
|
2023-03-12 20:51:45 +01:00
|
|
|
|
|
|
|
return Book
|
|
|
|
}
|