mirror of
https://framagit.org/les/gancio.git
synced 2025-02-01 00:52:01 +01:00
Merge branch 'dev' into vuetify
This commit is contained in:
commit
6ec1a0a2e3
5 changed files with 59 additions and 5 deletions
|
@ -24,6 +24,7 @@ const eventController = {
|
|||
|
||||
async _getMeta () {
|
||||
const places = await Place.findAll({
|
||||
where: { confirmed: true },
|
||||
order: [[Sequelize.literal('weigth'), 'DESC']],
|
||||
attributes: {
|
||||
include: [[Sequelize.fn('count', Sequelize.col('events.placeId')), 'weigth']],
|
||||
|
@ -34,6 +35,7 @@ const eventController = {
|
|||
})
|
||||
|
||||
const tags = await Tag.findAll({
|
||||
where: { confirmed: true },
|
||||
raw: true,
|
||||
order: [['weigth', 'DESC']],
|
||||
attributes: {
|
||||
|
@ -161,7 +163,7 @@ const eventController = {
|
|||
*/
|
||||
async confirm (req, res) {
|
||||
const id = Number(req.params.event_id)
|
||||
const event = await Event.findByPk(id)
|
||||
const event = await Event.findByPk(id, { include: [Place, Tag] })
|
||||
if (!event) { return res.sendStatus(404) }
|
||||
if (!req.user.is_admin && req.user.id !== event.userId) {
|
||||
return res.sendStatus(403)
|
||||
|
@ -169,6 +171,15 @@ const eventController = {
|
|||
|
||||
try {
|
||||
event.is_visible = true
|
||||
|
||||
// confirm tag & place if needed
|
||||
if (!event.place.confirmed) {
|
||||
await event.place.update({ confirmed: true })
|
||||
}
|
||||
|
||||
await Tag.update({ confirmed: true },
|
||||
{ where: { confirmed: false, tag: { [Op.in]: event.tags.map(t => t.tag) } } })
|
||||
|
||||
await event.save()
|
||||
|
||||
res.sendStatus(200)
|
||||
|
@ -277,7 +288,10 @@ const eventController = {
|
|||
|
||||
const [place] = await Place.findOrCreate({
|
||||
where: { name: body.place_name },
|
||||
defaults: { address: body.place_address }
|
||||
defaults: {
|
||||
address: body.place_address,
|
||||
confirmed: !!req.user
|
||||
}
|
||||
})
|
||||
|
||||
await event.setPlace(place)
|
||||
|
@ -285,7 +299,7 @@ const eventController = {
|
|||
|
||||
// create/assign tags
|
||||
if (body.tags) {
|
||||
await Tag.bulkCreate(body.tags.map(t => ({ tag: t })), { ignoreDuplicates: true })
|
||||
await Tag.bulkCreate(body.tags.map(t => ({ tag: t, confirmed: !!req.user })), { ignoreDuplicates: true })
|
||||
const tags = await Tag.findAll({ where: { tag: { [Op.in]: body.tags } } })
|
||||
await Promise.all(tags.map(t => t.update({ weigth: Number(t.weigth) + 1 })))
|
||||
await event.addTags(tags)
|
||||
|
|
|
@ -11,7 +11,12 @@ Place.init({
|
|||
index: true,
|
||||
allowNull: false
|
||||
},
|
||||
address: DataTypes.STRING
|
||||
address: DataTypes.STRING,
|
||||
confirmed: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true,
|
||||
allowNull: false
|
||||
}
|
||||
}, { sequelize, modelName: 'place' })
|
||||
|
||||
// Place.hasMany(Event)
|
||||
|
|
|
@ -11,7 +11,16 @@ Tag.init({
|
|||
index: true,
|
||||
primaryKey: true
|
||||
},
|
||||
weigth: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false }
|
||||
weigth: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false
|
||||
},
|
||||
confirmed: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true,
|
||||
allowNull: false
|
||||
}
|
||||
}, { sequelize, modelName: 'tag' })
|
||||
|
||||
// Tag.belongsToMany(Event, { through: 'event_tags' })
|
||||
|
|
13
server/migrations/20200831143500-tag_confirmation.js
Normal file
13
server/migrations/20200831143500-tag_confirmation.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.addColumn('tags', 'confirmed', {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: true,
|
||||
allowNull: false
|
||||
})
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.removeColumn('tags', 'confirmed')
|
||||
}
|
||||
}
|
13
server/migrations/20200831144116-place_confirmation.js
Normal file
13
server/migrations/20200831144116-place_confirmation.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.addColumn('places', 'confirmed', {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: true,
|
||||
allowNull: false
|
||||
})
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.removeColumn('places', 'confirmed')
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue