/* global __appdir */ const path = require('path') var db = require(path.join(__appdir, 'lib', 'sequelize')) async function log ({ category, description, clientId, userId, groupId, group, client, user }) { const entry = db.log.build({ category, description, timestamp: Date.now() / 1000, groupId, clientId, userId }) if (group) entry.groupSnapshot = JSON.stringify(group) else if (groupId) entry.groupSnapshot = JSON.stringify(await db.group.findOne({ where: { id: groupId } })) if (client) entry.clientSnapshot = JSON.stringify(client) else if (clientId) entry.clientSnapshot = JSON.stringify(await db.client.findOne({ where: { id: clientId } })) if (user) entry.userSnapshot = JSON.stringify(user) else if (userId) entry.userSnapshot = JSON.stringify(await db.user.findOne({ where: { id: userId } })) await entry.save() return entry } module.exports = log