Make readBy and unreadBy random

This commit is contained in:
Mikołaj Pich 2021-08-29 13:18:52 +02:00
parent f56e7e29df
commit 04e11925ac
2 changed files with 13 additions and 2 deletions

View file

@ -2,6 +2,7 @@ const express = require('express');
const router = express.Router();
const protocol = require('../utils/connection');
const converter = require('../utils/converter');
const {getRandomInt} = require("../utils/api");
const md5 = require('md5');
router.get("/", (req, res) => {
@ -38,14 +39,17 @@ router.get("/-endpoints", (req, res) => {
});
router.get("/Wiadomosc.mvc/GetInboxMessages", (req, res) => {
const recipientsNumber = getRandomInt(60, 100);
const readBy = getRandomInt(20, 60);
const unreadBy = recipientsNumber - readBy;
res.json({
"success": true,
"data": require("../../data/api/messages/WiadomosciOdebrane").map(item => {
return {
"Id": item.WiadomoscId * 2,
"Nieprzeczytana": !item.GodzinaPrzeczytania,
"Nieprzeczytane": 0,
"Przeczytane": 1,
"Nieprzeczytane": unreadBy,
"Przeczytane": readBy,
"Data": converter.formatDate(new Date(item.DataWyslaniaUnixEpoch * 1000), true) + ' 00:00:00',
"Tresc": null,
"Temat": item.Tytul,

View file

@ -12,4 +12,11 @@ function createResponse(data) {
};
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
exports.createResponse = createResponse;
exports.getRandomInt = getRandomInt;