Region/district/city bounds routes

This commit is contained in:
cracklesparkle
2025-01-14 14:32:41 +09:00
parent 2bf657e8ed
commit e6b3dc05d3
6 changed files with 132 additions and 46 deletions

View File

@ -1,8 +1,73 @@
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('/bounds/:entity_type', async (req: Request, res: Response) => {
try {
const { entity_type } = req.params
const result = await pgQuery(
`
SELECT * FROM bounds
WHERE entity_type = $1
`,
[entity_type]
)
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 }) => {
return {
...bound.geometry,
properties: {
id: bound.id,
entity_id: bound.entity_id,
entity_type: bound.entity_type
}
}
})
res.status(200).json(geometries)
} else {
res.status(404).json('not found')
}
} else {
res.status(404).json('not found')
}
} catch (err) {
res.status(500)
}
})
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
AND entity_id = $2
`,
[entity_type, entity_id]
)
if (Array.isArray(result)) {
if (result.length > 0) {
res.status(200).json(result[0].geometry)
} else {
res.status(404).json('not found')
}
} else {
res.status(404).json('not found')
}
} catch (err) {
res.status(500)
}
})
router.get('/images/all', async (req: Request, res: Response) => {
try {
const { offset, limit, city_id } = req.query