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










                                                                               





                                                                                                            






                                                                               
/* global __appdir */
var path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
var express = require('express')
const { decorateApp } = require('@awaitjs/express')
var router = decorateApp(express.Router())

// ############################################################################
// ###########################  GET requests  #################################

router.getAsync('', async (req, res) => {
  const log = await db.log.findAll({ include: ['group', 'client', 'user'], order: [['timestamp', 'DESC']] })
  log.forEach(entry => {
    if (entry.clientSnapshot) entry.clientSnapshot = JSON.parse(entry.clientSnapshot)
    if (entry.groupSnapshot) entry.groupSnapshot = JSON.parse(entry.groupSnapshot)
    if (entry.userSnapshot) entry.userSnapshot = JSON.parse(entry.userSnapshot)
  })
  res.send(log)
})

// ############################################################################
// ############################################################################

module.exports.router = router