UNPKG

@ozmap/logger

Version:
24 lines (23 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const errors_1 = require("../errors"); const Events_1 = require("../../util/Events"); const Helpers_1 = require("../../util/Helpers"); exports.default = { 'POST /changeLevel': async (req, res) => { if (!req.reqIsJson) throw new errors_1.HttpError(`Request content must be of type JSON.`, 409); if (!(0, Helpers_1.isJsonObject)(req.body)) throw new errors_1.HttpError(`Invalid request payload. Data must be a key/value pair object.`, 409); const data = req.body; if (!('level' in data)) throw new errors_1.HttpError(`Request is missing 'level' parameter.`, 409); if (typeof data.level !== 'string') throw new errors_1.HttpError(`Request parameter 'level' must be a string.`, 409); if (!('duration' in data)) throw new errors_1.HttpError(`Request is missing 'duration' parameter.`, 409); if (typeof data.duration !== 'number' || data.duration < 1) throw new errors_1.HttpError(`Request parameter 'duration' must be a non zero positive integer.`, 409); (0, Events_1.broadcastEvent)('ozlogger.http.changeLevel', data); } };