This commit is contained in:
lesion
2019-05-30 12:12:51 +02:00
parent 6099d538c0
commit 745b9247c9
46 changed files with 543 additions and 181 deletions

View File

@@ -12,6 +12,7 @@ moment.locale('it')
const botController = {
bot: null,
async initialize () {
console.error('dentro bot inizialiteds')
const settings = await settingsController.settings()
if (!settings.mastodon_auth || !settings.mastodon_auth.access_token) return
const mastodon_auth = settings.mastodon_auth

View File

@@ -21,24 +21,22 @@ const eventController = {
async getMeta(req, res) {
const places = await Place.findAll({
group: ['place.id'],
order: [[Sequelize.fn("COUNT", Sequelize.col('events.id')), 'DESC']],
order: [[Sequelize.literal('weigth'), 'DESC']],
attributes: {
include: [[Sequelize.fn("COUNT", Sequelize.col('events.id')), 'eventsCount']],
exclude: ['createdAt', 'updatedAt']
include: [[Sequelize.fn('count', Sequelize.col('events.placeId')) ,'weigth']], // <---- Here you will get the total count of user
exclude: ['weigth', 'createdAt', 'updatedAt']
},
include: { model: Event, attributes: [] }
include: [{ model: Event, attributes: [] }],
group: ['place.id']
})
const tags = await Tag.findAll({
group: ['tag'],
order: [[Sequelize.fn("COUNT", Sequelize.col('events.id')), 'DESC']],
includeIgnoreAttributes:false,
order: [['weigth' , 'DESC']],
includeIgnoreAttributes: false,
attributes: {
include: [[Sequelize.fn("COUNT", Sequelize.col('events.id')), 'eventsCount']],
exclude: ['createdAt', 'updatedAt']
},
include: { model: Event, attributes: [] }})
}
})
res.json({ tags, places })
},
@@ -92,7 +90,7 @@ const eventController = {
Comment,
{ model: Place, attributes: ['name', 'address'] }
] ,
order: [ [Comment, 'id', 'DESC'] ]
order: [ [Comment, 'id', 'DESC'], [Tag, 'weigth', 'DESC'] ]
})
res.json(event)
},
@@ -177,15 +175,17 @@ const eventController = {
{ start_datetime: { [Op.lte]: end } }
]
},
order: [['start_datetime', 'ASC']],
order: [
['start_datetime', 'ASC'],
[Tag, 'weigth', 'DESC']
],
include: [
{ model: User, required: false },
Comment,
Tag,
{ model: Place, required: false }
// { model: User, required: false },
// { type: Comment, required: false, attributes: ['']
{ model: Tag, required: false, attributes: ['tag', 'weigth','color'] },
{ model: Place, required: false, attributes: ['id', 'name', 'address'] }
]
})
// console.log(events)
res.json(events)
}

View File

@@ -8,6 +8,7 @@ const exportController = {
async export (req, res) {
console.log('type ', req.params.type)
console.error(req)
const type = req.params.type
const tags = req.query.tags
const places = req.query.places
@@ -18,14 +19,20 @@ const exportController = {
whereTag.tag = tags.split(',')
}
if (places) {
wherePlace.name = places.split(',')
wherePlace.id = places.split(',')
}
console.error(places)
const events = await Event.findAll({
where: { is_visible: true, start_datetime: { [Op.gte]: yesterday } },
include: [Comment, {
model: Tag,
where: whereTag
}, { model: Place, where: wherePlace } ]
order: ['start_datetime'],
where: {
is_visible: true,
start_datetime: { [Op.gte]: yesterday },
placeId: places.split(',')
},
attributes: {
exclude: ['createdAt', 'updatedAt']
},
include: [{model: Place, attributes: ['name', 'id', 'address', 'weigth']}]
})
switch (type) {
case 'feed':

View File

@@ -74,17 +74,14 @@ const userController = {
async addEvent(req, res) {
const body = req.body
// remove description tag and create anchor tags
const description = body.description
.replace(/(<([^>]+)>)/ig, '')
.replace(/(https?:\/\/[^\s]+)/g, '<a href="$1">$1</a>')
const eventDetails = {
title: body.title,
description,
description: body.description.replace(/(<([^>]+)>)/ig, ''),
multidate: body.multidate,
start_datetime: body.start_datetime,
end_datetime: body.end_datetime,
// publish this event if authenticated
is_visible: !!req.user
}
@@ -94,7 +91,7 @@ const userController = {
let event = await Event.create(eventDetails)
// create place
// create place if needs to
let place
try {
place = await Place.findOrCreate({ where: { name: body.place_name },
@@ -140,7 +137,7 @@ const userController = {
body.description = body.description
.replace(/(<([^>]+)>)/ig, '') // remove all tags from description
.replace(/(https?:\/\/[^\s]+)/g, '<a href="$1">$1</a>') // add links
// .replace(/(https?:\/\/[^\s]+)/g, '<a href="$1">$1</a>') // add links
await event.update(body)
let place