Verified Commit 1edf6b17 authored by les's avatar les
Browse files

let's slugifyyyy

parent af106787
<template lang="pug">
v-card.h-event.event
nuxt-link(:to='`/event/${event.id}`')
nuxt-link(:to='`/event/${event.slug || event.id}`')
v-img.img(:src="`/media/thumb/${event.image_path || 'logo.svg' }`")
v-icon.float-right.mr-1(v-if='event.parentId' color='success') mdi-repeat
.title.p-name {{event.title}}
......@@ -43,4 +43,4 @@ export default {
},
computed: mapState(['settings'])
}
</script>
\ No newline at end of file
</script>
......@@ -86,14 +86,21 @@ const eventController = {
},
async get (req, res) {
log.error('get')
const format = req.params.format || 'json'
const is_admin = req.user && req.user.is_admin
const id = Number(req.params.event_id)
const slug = req.params.event_id
const id = Number(req.params.event_id) || -1
console.error(slug)
let event
try {
event = await Event.findByPk(id, {
event = await Event.findOne({
where: {
[Op.or]: {
slug,
id
}
},
attributes: {
exclude: ['createdAt', 'updatedAt', 'placeId']
},
......@@ -112,6 +119,7 @@ const eventController = {
order: [[Resource, 'id', 'DESC']]
})
} catch (e) {
console.error(e)
return res.sendStatus(400)
}
......@@ -119,6 +127,7 @@ const eventController = {
return res.sendStatus(400)
}
console.error('diocane')
// get prev and next event
const next = await Event.findOne({
attributes: ['id'],
......@@ -446,7 +455,7 @@ const eventController = {
const events = await Event.findAll({
where,
attributes: {
exclude: ['slug', 'likes', 'boost', 'userId', 'is_visible', 'createdAt', 'updatedAt', 'description', 'resources']
exclude: ['likes', 'boost', 'userId', 'is_visible', 'createdAt', 'updatedAt', 'description', 'resources']
},
order: ['start_datetime', Sequelize.literal('(SELECT COUNT("tagTag") FROM event_tags WHERE "tagTag" = tag) DESC')],
include: [
......
......@@ -3,6 +3,8 @@ const moment = require('dayjs')
const htmlToText = require('html-to-text')
const { Model, DataTypes } = require('sequelize')
const SequelizeSlugify = require('sequelize-slugify')
const sequelize = require('./index')
const Resource = require('./resource')
......@@ -26,7 +28,11 @@ Event.init({
autoIncrement: true
},
title: DataTypes.STRING,
slug: DataTypes.STRING,
slug: {
type: DataTypes.STRING,
index: true,
unique: true
},
description: DataTypes.TEXT,
multidate: DataTypes.BOOLEAN,
start_datetime: {
......@@ -62,6 +68,8 @@ Resource.belongsTo(Event)
Event.hasMany(Event, { as: 'child', foreignKey: 'parentId' })
Event.belongsTo(Event, { as: 'parent' })
SequelizeSlugify.slugifyModel(Event, { source: ['title'] })
Event.prototype.toAPNote = function (username, locale, to = []) {
const tags = this.tags && this.tags.map(t => t.tag.replace(/[ #]/g, '_'))
const plainDescription = htmlToText.fromString(this.description && this.description.replace('\n', '').slice(0, 1000))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment