summaryrefslogtreecommitdiffstats
path: root/server/lib/log.js
blob: 22ce264a63c8e2386e54019053620d85acaefd1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* 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 = await db.group.findOne({ where: { id: groupId }})
  if (clientId)  entry.clientSnapshot = await db.client.findOne({ where: { id: clientId }})
  if (userId) entry.userSnapshot = await db.user.findOne({ where: { id: userId }})
  await entry.save()
  return entry
}

module.exports = log