From 4758e919c59c2f342a5b5f3e4c1e02494f860040 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Fri, 15 Mar 2019 04:47:09 +0000 Subject: [server/log] add log lib --- server/lib/log.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 server/lib/log.js (limited to 'server/lib/log.js') diff --git a/server/lib/log.js b/server/lib/log.js new file mode 100644 index 0000000..22ce264 --- /dev/null +++ b/server/lib/log.js @@ -0,0 +1,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 \ No newline at end of file -- cgit v1.2.3-55-g7522