diff --git a/src/db.js b/src/db.js index c039654870118f88ced6c0b89edae4bdbd55a2dd..b69de164746aa138ef1b2a6447ada13aa342939e 100644 --- a/src/db.js +++ b/src/db.js @@ -2,6 +2,11 @@ const { Sequelize } = require("sequelize"); const departments = require("./models/department"); const medias = require("./models/medium"); const mediatypes = require("./models/mediatype"); +const articles = require("./models/article"); +const articleThemes = require("./models/article_theme"); +const pressRelease = require("./models/press_release") +const pressReleaseTypes = require("./models/press_release_type") +const pressReleaseThemes = require("./models/press_release_theme") const sequelize = new Sequelize({ dialect: "postgres", @@ -27,8 +32,14 @@ sequelize departments(sequelize); medias(sequelize); mediatypes(sequelize); +articles(sequelize); +articleThemes(sequelize); +pressRelease(sequelize); +pressReleaseTypes(sequelize); +pressReleaseThemes(sequelize); -const { Department, Media, Mediatype } = require("./models/associations")( + +const { Department, Media, Mediatype, PressRelease, PressReleaseTheme, PressReleaseType, Article, ArticleTheme } = require("./models/associations")( sequelize ); diff --git a/src/models/article.js b/src/models/article.js index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..85f6193e118b7fda5a8a6aeb031435f30d05ce1a 100644 --- a/src/models/article.js +++ b/src/models/article.js @@ -0,0 +1,29 @@ +const { DataTypes, Model } = require('sequelize'); + +class Article extends Model {} + +module.exports = function(sequelize) { + Article.init({ + _id: { + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, + primaryKey: true, + }, + title: { + type: DataTypes.TEXT, + allowNull: false, + }, + date: { + type: DataTypes.DATEONLY, + allowNull: false, + defaultValue: DataTypes.DATEONLY + }, + tone: { + type: DataTypes.ENUM('positive', 'negative'), + allowNull: false + }, + }, { + sequelize, + modelName: "Article" + }) +} \ No newline at end of file diff --git a/src/models/associations.js b/src/models/associations.js index 65990871bb053ccb8bc43b5385d5e4092fba0a57..9ffdbe397650024a8bf99bb188adff55a4bdd20c 100644 --- a/src/models/associations.js +++ b/src/models/associations.js @@ -2,6 +2,11 @@ module.exports = (sequelize) => { const Department = sequelize.models.Department; const Media = sequelize.models.Media; const Mediatype = sequelize.models.Mediatype; + const PressRelease = sequelize.models.PressRelease; + const PressReleaseTheme = sequelize.models.PressReleaseTheme; + const PressReleaseType = sequelize.models.PressReleaseType; + const Article = sequelize.models.Article; + const ArticleTheme = sequelize.models.ArticleTheme; Department.belongsToMany(Media, { through: "DepartmentMedia", @@ -15,5 +20,29 @@ module.exports = (sequelize) => { Mediatype.hasMany(Media, { onDelete: "RESTRICT" }); Media.belongsTo(Mediatype); - return { Department, Media, Mediatype }; + PressRelease.belongsToMany(PressReleaseTheme, { + through: "PRThemePressRelease", + onDelete: "CASCADE" + }); + PressReleaseTheme.belongsToMany(PressRelease, { + through: "PRThemePressRelease", + onDelete: "RESTRICT" + }); + + PressReleaseType.hasMany(PressRelease, { onDelete: "RESTRICT" }); + PressRelease.belongsTo(PressReleaseType); + + Article.belongsToMany(ArticleTheme, { + through: "ArticleThemeArticle", + onDelete: "CASCADE" + }); + ArticleTheme.belongsToMany(Article, { + through: "ArticleThemeArticle", + onDelete: "RESTRICT" + }); + + PressRelease.hasMany(Article, { onDelete: "RESTRICT" }); + Article.belongsTo(PressRelease, { onDelete: "RESTRICT" }); + + return { Department, Media, Mediatype, PressRelease, PressReleaseTheme, PressReleaseType, Article, ArticleTheme }; }; diff --git a/src/models/press_release.js b/src/models/press_release.js index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..97ee8cabba77d0f9d33ded8476e93cdfaec74819 100644 --- a/src/models/press_release.js +++ b/src/models/press_release.js @@ -0,0 +1,25 @@ +const { DataTypes, Model } = require('sequelize'); + +class PressRelease extends Model {} + +module.exports = function(sequelize) { + PressRelease.init({ + _id: { + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, + primaryKey: true, + }, + title: { + type: DataTypes.TEXT, + allowNull: false, + }, + date: { + type: DataTypes.DATEONLY, + allowNull: false, + defaultValue: DataTypes.DATEONLY + }, + }, { + sequelize, + modelName: "PressRelease" + }) +} \ No newline at end of file diff --git a/src/models/press_release_theme.js b/src/models/press_release_theme.js index 664bf3d0de950346b6c1396d0dce18d615888487..7f41941b3a0a01779ee63a0b92f28142755f75e7 100644 --- a/src/models/press_release_theme.js +++ b/src/models/press_release_theme.js @@ -17,7 +17,7 @@ module.exports = function(sequelize) { }, }, { sequelize, - modelName: "PRTheme" + modelName: "PressReleaseTheme" } ) } \ No newline at end of file diff --git a/src/models/press_release_type.Js b/src/models/press_release_type.js similarity index 92% rename from src/models/press_release_type.Js rename to src/models/press_release_type.js index fe15471fa8a705cb9edc739f8059954ed4cc72a6..300b27ae8a6a31605d863fa4e6ea27f80ef9e602 100644 --- a/src/models/press_release_type.Js +++ b/src/models/press_release_type.js @@ -17,7 +17,7 @@ module.exports = function(sequelize) { }, }, { sequelize, - modelName: "PRType" + modelName: "PressReleaseType" } ) } \ No newline at end of file