nestjs rewrite

This commit is contained in:
popovspiridon99
2025-08-01 11:08:33 +09:00
parent 1f9a3a8e03
commit 145827ab6d
28 changed files with 1220 additions and 623 deletions

View File

@ -2,8 +2,22 @@ import express, { Request, Response } from 'express';
import { tediousQuery } from '../../utils/tedious';
import { GeneralDB, GisDB } from '../../constants/db';
import { pgQuery } from '../../utils/postgres';
const router = express.Router()
router.get('/migrate/lines', async (req: Request, res: Response) => {
try {
const result = await tediousQuery(
`
SELECT * FROM ${GisDB}..lines
`
)
} catch (error) {
res.status(500)
}
})
// ✅
router.get('/type-roles', async (req: Request, res: Response) => {
try {
const result = await tediousQuery(
@ -17,13 +31,15 @@ router.get('/type-roles', async (req: Request, res: Response) => {
}
})
// ✅
router.get('/bounds/:entity_type', async (req: Request, res: Response) => {
try {
const { entity_type } = req.params
const result = await pgQuery(
`
SELECT * FROM bounds
SELECT entity_id, entity_type, ST_AsGeoJSON(geometry)::JSON AS geometry FROM bounds
WHERE entity_type = $1
`,
[entity_type]
@ -31,7 +47,7 @@ router.get('/bounds/:entity_type', async (req: Request, res: Response) => {
if (Array.isArray(result)) {
if (result.length > 0) {
const geometries = result.map((bound: { id: number, entity_id: number, entity_type: string, geometry: JSON, published_at: string, deleted_at: string | null }) => {
const geometries = result.map((bound: { id: string, entity_id: number, entity_type: string, geometry: JSON, published_at: string, deleted_at: string | null }) => {
return {
...bound.geometry,
properties: {
@ -54,14 +70,15 @@ router.get('/bounds/:entity_type', async (req: Request, res: Response) => {
}
})
// ✅
router.get('/bounds/:entity_type/:entity_id', async (req: Request, res: Response) => {
try {
const { entity_type, entity_id } = req.params
const result = await pgQuery(
`
SELECT * FROM bounds
WHERE entity_type = $1
SELECT entity_id, entity_type, ST_AsGeoJSON(geometry)::JSON AS geometry FROM bounds
WHERE entity_type = $1
AND entity_id = $2
`,
[entity_type, entity_id]
@ -81,6 +98,7 @@ router.get('/bounds/:entity_type/:entity_id', async (req: Request, res: Response
}
})
// ✅
router.get('/images/all', async (req: Request, res: Response) => {
try {
const { offset, limit, city_id } = req.query
@ -100,7 +118,7 @@ router.get('/images/all', async (req: Request, res: Response) => {
}
})
// ✅
// Get figures by year and city id
router.get('/figures/all', async (req: Request, res: Response) => {
try {
@ -121,6 +139,7 @@ router.get('/figures/all', async (req: Request, res: Response) => {
}
})
// ✅
// Get lines by year and city id
router.get('/lines/all', async (req: Request, res: Response) => {
try {
@ -138,6 +157,7 @@ router.get('/lines/all', async (req: Request, res: Response) => {
}
})
// ✅
router.get('/regions/borders', async (req: Request, res: Response) => {
try {
const result = await tediousQuery(