summaryrefslogblamecommitdiffstats
path: root/server/lib/log.js
blob: 3b5dcd3a4462d6a1734d2b7db7c24df643222e35 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                                           


                                                                                                          



                    
                   
/* global __appdir */
const path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))

async function log ({ category, description, groupId, clientId, userId }) {
  const entry = db.log.build({
    category,
    description,
    timestamp: Date.now() / 1000,
    groupId,
    clientId,
    userId
  })
  if (groupId) entry.groupSnapshot = JSON.stringify(await db.group.findOne({ where: { id: groupId }}))
  if (clientId) entry.clientSnapshot = JSON.stringify(await db.client.findOne({ where: { id: clientId }}))
  if (userId) entry.userSnapshot = JSON.stringify(await db.user.findOne({ where: { id: userId }}))
  await entry.save()
  return entry
}

module.exports = log