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

62 lines
2 KiB
JavaScript
Raw Normal View History

2019-07-31 01:03:21 +02:00
const config = require('config')
2019-08-07 19:36:10 +02:00
const moment = require('moment')
2019-07-31 01:03:21 +02:00
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,
2019-07-11 23:31:37 +02:00
recurrent: DataTypes.JSON,
// parent: DataTypes.INTEGER
2019-08-01 15:18:45 +02:00
likes: { type: DataTypes.JSON, defaultValue: [] },
boost: { type: DataTypes.JSON, defaultValue: [] }
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-08-25 14:51:38 +02:00
const tags = this.tags && '-' + this.tags.map(t => '#' + t.tag).join(' ')
const content = `<b><a href='${config.baseurl}/event/${this.id}'>${this.title}</a></b> @${this.place.name}
${moment.unix(this.start_datetime).format('dddd, D MMMM (HH:mm)')}<br/>
${this.description.length > 200 ? this.description.substr(0, 200) + '...' : this.description} ${tags} <br/>`
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-08-25 14:51:38 +02:00
content
2019-07-31 01:03:21 +02:00
}
}
}
2019-06-07 17:02:33 +02:00
return event
2019-06-09 00:45:50 +02:00
}