-
Notifications
You must be signed in to change notification settings - Fork 66
/
dashboard.ts
43 lines (39 loc) · 941 Bytes
/
dashboard.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { NextApiRequest, NextApiResponse } from "next";
type Data = {
visitor: {
value: number;
rate: number;
};
order: {
value: number;
rate: number;
};
income: {
value: number;
rate: number;
};
};
const getRandomInt = (min: number, max: number) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
};
const getRandomRate = (min: number, max: number) => {
return Math.round((Math.random() * (max - min) + min) * 10) / 10;
};
export default function handler(_req: NextApiRequest, res: NextApiResponse<Data>) {
res.status(200).json({
visitor: {
value: getRandomInt(1000, 10000),
rate: getRandomRate(-10, 50),
},
order: {
value: getRandomInt(10, 1000),
rate: getRandomRate(-10, 50),
},
income: {
value: getRandomInt(1000000, 10000000),
rate: getRandomRate(-10, 50),
},
});
}