summaryrefslogtreecommitdiffstats
path: root/server/lib/log.js
blob: fede8749cee17155778d3b739acaf0bb65617b7f (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 = 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