77 lines
2.0 KiB
JavaScript
77 lines
2.0 KiB
JavaScript
import express from "express";
|
|
import cors from "cors";
|
|
import ky from "ky";
|
|
|
|
const app = express();
|
|
const PORT = 3000;
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
|
|
app.get("/regions", async (req, res) => {
|
|
let regions = [];
|
|
|
|
const result = await ky
|
|
.get(
|
|
"https://xn--80az8a.xn--d1aqf.xn--p1ai/аналитика/квартирография/api/dictionaries/regions"
|
|
)
|
|
.json();
|
|
|
|
regions = result
|
|
.map((item) => item.regions)
|
|
.flat()
|
|
.sort((a, b) => (a.name > b.name ? 1 : -1))
|
|
.filter((region) => {
|
|
if (![79, 41, 51, 83, 6, 87].includes(region.id)) {
|
|
return region;
|
|
}
|
|
});
|
|
|
|
res.send(regions);
|
|
});
|
|
|
|
app.get("/region/:id", async (req, res) => {
|
|
try {
|
|
const result = await ky
|
|
.get(
|
|
`https://наш.дом.рф/аналитика/квартирография/api/dashboard/by-room-count?regions=${req.params.id}`
|
|
)
|
|
.json();
|
|
|
|
const result2 = await ky
|
|
.get(
|
|
`https://наш.дом.рф/аналитика/api/rpp/?regionCode=${req.params.id}&repMonth=3&repYear=2023`
|
|
)
|
|
.json();
|
|
const result3 = await ky
|
|
.get(
|
|
`https://наш.дом.рф/аналитика/api/developers/dashboard?sort=objSquareLivingAmt:desc&subjectTypes=region®ion=${req.params.id}&date=01-04-2023&limit=0`
|
|
)
|
|
.json();
|
|
|
|
const { totalArea, flatCount } = result;
|
|
const avgApartmentArea = Math.round(totalArea / flatCount);
|
|
|
|
const priceAvg = Math.round(result2.data.total[0].priceAvg / 1000);
|
|
|
|
const { objSquareLivingAmt, objCnt } = result3.data.total;
|
|
const avgAreaInComplex = Math.round(objSquareLivingAmt / objCnt);
|
|
|
|
res.send({ avgApartmentArea, priceAvg, avgAreaInComplex });
|
|
} catch (error) {
|
|
res.send({ error: 1 });
|
|
}
|
|
});
|
|
|
|
app.get("/test/:id", async (req, res) => {
|
|
try {
|
|
res.json({ data });
|
|
} catch (error) {
|
|
res.send({ error: 1 });
|
|
}
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Server is started on port ${PORT}...`);
|
|
});
|