Files
gancio/app/models/event.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-02-26 00:02:42 +01:00
const db = require('../db')
const Sequelize = require('sequelize')
const User = require('./user')
const Event = db.define('event', {
title: Sequelize.STRING,
2019-03-07 14:59:28 +01:00
description: Sequelize.TEXT,
2019-02-26 00:02:42 +01:00
multidate: Sequelize.BOOLEAN,
2019-02-26 01:17:52 +01:00
start_datetime: { type: Sequelize.DATE, index: true },
end_datetime: { type: Sequelize.DATE, index: true },
2019-02-26 00:02:42 +01:00
image_path: Sequelize.STRING,
2019-03-07 14:59:28 +01:00
activitypub_id: { type: Sequelize.INTEGER, index: true },
is_visible: Sequelize.BOOLEAN
2019-02-26 00:02:42 +01:00
})
const Tag = db.define('tag', {
2019-02-26 01:17:52 +01:00
tag: { type: Sequelize.STRING, index: true, unique: true, primaryKey: true },
2019-02-26 00:02:42 +01:00
color: { type: Sequelize.STRING }
})
const Comment = db.define('comment', {
activitypub_id: { type: Sequelize.INTEGER, index: true },
author: Sequelize.STRING,
2019-02-26 01:17:52 +01:00
text: Sequelize.STRING
2019-02-26 00:02:42 +01:00
})
2019-03-11 00:20:37 +01:00
const Notification = db.define('notification', {
2019-02-26 00:02:42 +01:00
filters: Sequelize.JSON,
2019-03-10 01:01:23 +01:00
email: Sequelize.STRING,
2019-03-11 00:20:37 +01:00
remove_code: Sequelize.STRING,
type: {
type: Sequelize.ENUM,
values: ['mail', 'admin_mail', 'mastodon']
2019-03-11 00:20:37 +01:00
}
2019-02-26 00:02:42 +01:00
})
Notification.findOrCreate({ where: { type: 'mastodon' } })
Notification.findOrCreate({ where: { type: 'admin_email' } })
2019-02-26 00:02:42 +01:00
const Place = db.define('place', {
name: { type: Sequelize.STRING, unique: true, index: true },
address: { type: Sequelize.STRING }
})
Comment.belongsTo(Event)
Event.hasMany(Comment)
2019-02-26 01:17:52 +01:00
Event.belongsToMany(Tag, { through: 'tagEvent' })
Tag.belongsToMany(Event, { through: 'tagEvent' })
2019-02-26 00:02:42 +01:00
2019-03-11 00:20:37 +01:00
const EventNotification = db.define('EventNotification')
Event.belongsToMany(Notification, { through: EventNotification })
Notification.belongsToMany(Event, { through: EventNotification })
2019-03-10 01:01:23 +01:00
2019-02-26 00:02:42 +01:00
Event.belongsTo(User)
Event.belongsTo(Place)
User.hasMany(Event)
Place.hasMany(Event)
2019-03-11 00:20:37 +01:00
module.exports = { Event, Comment, Tag, Place, Notification, EventNotification }