AppReports/lib/api/post-log.js
Timo Hocker 8a36273325
All checks were successful
continuous-integration/drone/push Build is passing
display info on reject log
2020-08-22 12:29:18 +02:00

39 lines
977 B
JavaScript

/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of appreports which is released under GPL-3.0-or-later.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, August 2020
*/
'use strict';
const db = require ('../db');
const { http } = require ('@sapphirecode/consts');
module.exports = async (req, res) => {
const { app_id } = req.headers;
if (
app_id === 'undefined'
|| isNaN (parseInt (app_id))
) {
console.log('bad request, did not receive app id');
res.status (http.status_bad_request)
.end ();
return;
}
const log = req.body;
if (typeof log !== 'object') {
console.log('bad request, did not receive data in json format');
res.status (http.status_bad_request)
.end ();
return;
}
const { message, data, timestamp } = log;
await db.log.insert (app_id, message, JSON.stringify (data), timestamp);
res.status (http.status_created)
.end ();
};