[refactor] s/fed_user/ap_user

This commit is contained in:
les
2019-12-04 01:20:31 +01:00
parent c43fe095a5
commit 5052ceca0a
17 changed files with 214 additions and 123 deletions

View File

@@ -0,0 +1,12 @@
const { ap_users: APUsers } = require('../models')
const apUserController = {
async toggleBlock (req, res) {
const user_id = req.body.user_id
const user = await APUsers.findByPk(user_id)
user.update({ blocked: !user.blocked })
res.json(user)
}
}
module.exports = apUserController

View File

@@ -1,27 +0,0 @@
const { fed_users: FedUsers, comment: Comment } = require('../models')
const fedUserController = {
async toggleBlock (req, res) {
const user_id = req.body.user_id
const user = await FedUsers.findByPk(user_id)
user.update({ blocked: !user.blocked })
res.json(user)
},
async hideComment (req, res) {
const comment_id = req.params.comment_id
const hidden = req.body.hidden
const comment = await Comment.findByPk(comment_id)
await comment.update({ hidden })
res.json(comment)
},
async removeComment (req, res) {
const comment_id = req.params.comment_id
const comment = await Comment.findByPk(comment_id)
await comment.destroy()
res.sendStatus(200)
}
}
module.exports = fedUserController

View File

@@ -1,14 +1,14 @@
const Sequelize = require('sequelize')
const { fed_users: FedUsers, instances: Instances, comment: Comment } = require('../models')
const { ap_user: APUser, instance: Instance, resource: Resource } = require('../models')
const instancesController = {
async getAll (req, res) {
const instances = await Instances.findAll({
const instances = await Instance.findAll({
attributes: {
include: [[Sequelize.fn('count', Sequelize.col('domain')), 'users']]
},
group: ['domain'],
include: [{ model: FedUsers, attributes: [] }]
include: [{ model: APUser, attributes: [] }]
})
return res.json(instances)
},
@@ -17,12 +17,12 @@ const instancesController = {
* get instance users
*/
async get (req, res) {
const fedi_users = await FedUsers.findAll({ where: { instanceDomain: req.params.instance_domain }, include: [Comment] })
const fedi_users = await APUser.findAll({ where: { instanceDomain: req.params.instance_domain }, include: [Resource] })
return res.json(fedi_users)
},
async toggleBlock (req, res) {
const instance = await Instances.findByPk(req.body.instance)
const instance = await Instance.findByPk(req.body.instance)
if (!instance) { return res.status(404).send('Not found') }
await instance.update({ blocked: req.body.blocked })
return res.json(instance)

View File

@@ -0,0 +1,18 @@
module.exports = (sequelize, DataTypes) => {
const APUser = sequelize.define('ap_user', {
ap_id: {
type: DataTypes.STRING,
primaryKey: true
},
follower: DataTypes.BOOLEAN,
blocked: DataTypes.BOOLEAN,
object: DataTypes.JSON
})
APUser.associate = function (models) {
APUser.belongsTo(models.instance)
APUser.hasMany(models.resource)
}
return APUser
}

View File

@@ -1,16 +0,0 @@
module.exports = (sequelize, DataTypes) => {
const fed_users = sequelize.define('fed_users', {
ap_id: {
type: DataTypes.STRING,
primaryKey: true
},
blocked: DataTypes.BOOLEAN,
object: DataTypes.JSON
}, {})
fed_users.associate = function (models) {
fed_users.belongsTo(models.instances)
fed_users.belongsToMany(models.user, { through: 'user_followers', as: 'followers' })
fed_users.hasMany(models.comment, { foreignKey: 'fedUserApId' })
}
return fed_users
}

View File

@@ -1,6 +1,6 @@
'use strict'
module.exports = (sequelize, DataTypes) => {
const instances = sequelize.define('instances', {
const Instance = sequelize.define('instance', {
domain: {
primaryKey: true,
allowNull: false,
@@ -11,9 +11,9 @@ module.exports = (sequelize, DataTypes) => {
data: DataTypes.JSON
}, {})
instances.associate = function (models) {
instances.hasMany(models.fed_users)
Instance.associate = function (models) {
Instance.hasMany(models.ap_user)
}
return instances
return Instance
}

View File

@@ -1,6 +1,6 @@
'use strict'
module.exports = (sequelize, DataTypes) => {
const notification = sequelize.define('notification', {
const Notification = sequelize.define('notification', {
filters: DataTypes.JSON,
email: DataTypes.STRING,
remove_code: DataTypes.STRING,
@@ -19,9 +19,9 @@ module.exports = (sequelize, DataTypes) => {
}]
})
notification.associate = function (models) {
notification.belongsToMany(models.event, { through: 'event_notification' })
Notification.associate = function (models) {
Notification.belongsToMany(models.event, { through: 'event_notification' })
// associations can be defined here
}
return notification
return Notification
}

View File

@@ -1,6 +1,7 @@
'use strict'
module.exports = (sequelize, DataTypes) => {
const place = sequelize.define('place', {
const Place = sequelize.define('place', {
name: {
type: DataTypes.STRING,
unique: true,
@@ -10,9 +11,9 @@ module.exports = (sequelize, DataTypes) => {
address: DataTypes.STRING
}, {})
place.associate = function (models) {
place.hasMany(models.event)
Place.associate = function (models) {
Place.hasMany(models.event)
}
return place
return Place
}

View File

@@ -1,6 +1,6 @@
'use strict'
module.exports = (sequelize, DataTypes) => {
const tag = sequelize.define('tag', {
const Tag = sequelize.define('tag', {
tag: {
type: DataTypes.STRING,
allowNull: false,
@@ -10,9 +10,9 @@ module.exports = (sequelize, DataTypes) => {
weigth: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false }
}, {})
tag.associate = function (models) {
tag.belongsToMany(models.event, { through: 'event_tags' })
Tag.associate = function (models) {
Tag.belongsToMany(models.event, { through: 'event_tags' })
}
return tag
return Tag
}