manga-server/models/manga.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-10-05 08:07:31 +00:00
const { DataTypes } = require('sequelize');
const sequelize = require('../config');
const Chapter = require('./chapter');
const Manga = sequelize.define('Manga', {
connectorId: {
type: DataTypes.STRING,
allowNull: false,
},
connectorName: {
type: DataTypes.STRING,
allowNull: false,
},
title: {
type: DataTypes.TEXT,
allowNull: false,
},
imageUrl: {
type: DataTypes.TEXT,
allowNull: false,
},
linkChapter: {
type: DataTypes.TEXT,
allowNull: false,
},
isFavorite: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
description: {
type: DataTypes.TEXT,
allowNull: false,
},
categories: {
type: DataTypes.JSON, // Stocke la liste des catégories
allowNull: false,
},
rate: {
type: DataTypes.TEXT,
defaultValue: '0',
},
});
Manga.hasMany(Chapter, { as: 'chapters', foreignKey: 'mangaId' });
Chapter.belongsTo(Manga, { foreignKey: 'mangaId' });
module.exports = Manga;