const { Router } = require('express')
const router = Router()
const os = require('os')
const { QueryTypes } = require('sequelize')
const db = require('../models')
const pkgJson = require('../package.json')

// Versions
router.get('/overlord/rest/v1/version', async (req, res) => {
  const result = await db.sequelize
    .query('SELECT version() as version_database', {
      type: QueryTypes.SELECT
    })

  // console.log(result[0].version_database)

  const version = {
    versionDatabase: result[0].version_database.substring(0, 15),
    versionNode: process.version,
    versionOS: os.platform() + ' ' + os.release(),
    version: pkgJson.version
  }

  res.json(version)
})

module.exports = router
