gancio-upstream/server/api/models/event.js

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-07-31 01:03:21 +02:00
const config = require('config')
2019-06-06 23:54:32 +02:00
module.exports = (sequelize, DataTypes) => {
const event = sequelize.define('event', {
2019-07-11 23:31:37 +02:00
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
2019-06-06 23:54:32 +02:00
title: DataTypes.STRING,
slug: DataTypes.STRING,
description: DataTypes.TEXT,
multidate: DataTypes.BOOLEAN,
2019-06-07 17:02:33 +02:00
start_datetime: {
type: DataTypes.INTEGER,
index: true
},
end_datetime: {
type: DataTypes.INTEGER,
2019-06-06 23:54:32 +02:00
index: true
},
image_path: DataTypes.STRING,
is_visible: DataTypes.BOOLEAN,
activitypub_id: {
2019-06-25 01:05:38 +02:00
type: DataTypes.STRING(18),
2019-06-06 23:54:32 +02:00
index: true
2019-06-25 01:05:38 +02:00
},
2019-07-11 23:31:37 +02:00
recurrent: DataTypes.JSON,
// parent: DataTypes.INTEGER
2019-06-07 17:02:33 +02:00
}, {})
2019-06-26 14:44:21 +02:00
2019-06-07 17:02:33 +02:00
event.associate = function (models) {
2019-06-06 23:54:32 +02:00
event.belongsTo(models.place)
event.belongsTo(models.user)
event.belongsToMany(models.tag, { through: 'event_tags' })
event.belongsToMany(models.notification, { through: 'event_notification' })
event.hasMany(models.comment)
2019-06-07 17:02:33 +02:00
}
2019-06-26 14:44:21 +02:00
2019-07-31 01:43:08 +02:00
event.prototype.toAP = function (username, follower) {
2019-07-31 01:03:21 +02:00
return {
id: `${config.baseurl}/federation/m/c_${this.id}`,
type: 'Create',
actor: `${config.baseurl}/federation/u/${username}`,
object: {
id: `${config.baseurl}/federation/m/${this.id}`,
type: 'Note',
published: this.createdAt,
attributedTo: `${config.baseurl}/federation/u/${username}`,
to: 'https://www.w3.org/ns/activitystreams#Public',
2019-07-31 01:50:55 +02:00
cc: follower ? follower: [],
2019-07-31 01:03:21 +02:00
content: this.title
}
}
}
2019-06-07 17:02:33 +02:00
return event
2019-06-09 00:45:50 +02:00
}