summaryrefslogtreecommitdiffstats
path: root/server/lib/log.js
diff options
context:
space:
mode:
authorUdo Walter2019-03-15 05:47:09 +0100
committerUdo Walter2019-03-15 05:47:09 +0100
commit4758e919c59c2f342a5b5f3e4c1e02494f860040 (patch)
treede8cae4339faee0b777b40ed3d7de1bf619e25d0 /server/lib/log.js
parent[server] New clients are automaticly added to the groups of the fitting subra... (diff)
downloadbas-4758e919c59c2f342a5b5f3e4c1e02494f860040.tar.gz
bas-4758e919c59c2f342a5b5f3e4c1e02494f860040.tar.xz
bas-4758e919c59c2f342a5b5f3e4c1e02494f860040.zip
[server/log] add log lib
Diffstat (limited to 'server/lib/log.js')
-rw-r--r--server/lib/log.js21
1 files changed, 21 insertions, 0 deletions
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