nestjs rewrite

This commit is contained in:
popovspiridon99
2025-08-01 11:33:40 +09:00
parent 145827ab6d
commit 37bfa912a0
58 changed files with 17130 additions and 0 deletions

View File

@ -0,0 +1,110 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectDataSource } from '@nestjs/typeorm';
import { DataSource } from 'typeorm';
@Injectable()
export class GisService {
constructor(
@InjectDataSource('sqliteConnection')
private dataSource: DataSource,
@InjectDataSource('emsConnection')
private emsDataSource: DataSource
) { }
async getTypeRoles(): Promise<any[]> {
const result = await this.emsDataSource.query(`
SELECT * FROM New_Gis..TypeRoles;
`)
return result
}
async getBoundsByEntityType(entity_type: 'region' | 'district' | 'city'): Promise<any[]> {
const result = await this.dataSource.query(`
SELECT entity_id, entity_type, geometry FROM bounds
WHERE entity_type = $1
`, [entity_type])
if (Array.isArray(result)) {
if (result.length > 0) {
const geometries = result.map((bound: { id: string, entity_id: number, entity_type: string, geometry: string, published_at: string, deleted_at: string | null }) => {
return {
...(JSON.parse(bound.geometry)),
properties: {
id: bound.id,
entity_id: bound.entity_id,
entity_type: bound.entity_type
}
}
})
return geometries
} else {
throw new NotFoundException('not found')
}
} else {
throw new NotFoundException('not found')
}
}
async getBoundsByEntityTypeAndId(entity_type: 'region' | 'district' | 'city', entity_id: number): Promise<any[]> {
const result = await this.dataSource.query(`
SELECT entity_id, entity_type, geometry FROM bounds
WHERE entity_type = $1
AND entity_id = $2
`, [entity_type, entity_id])
if (Array.isArray(result)) {
if (result.length > 0) {
return JSON.parse(result[0].geometry)
} else {
throw new NotFoundException('not found')
}
} else {
throw new NotFoundException('not found')
}
}
async getImages(offset: number, limit: number, city_id: number): Promise<any[]> {
const result = await this.emsDataSource.query(`
SELECT * FROM images
${city_id ? `WHERE city_id = ${city_id}` : ''}
ORDER BY city_id
OFFSET ${Number(offset) || 0} ROWS
FETCH NEXT ${Number(limit) || 10} ROWS ONLY;
`)
return result
}
async getFigures(offset: number, limit: number, year: number, city_id: number): Promise<any[]> {
const result = await this.emsDataSource.query(`
SELECT * FROM figures f
JOIN nGeneral..vObjects o ON f.object_id = o.object_id WHERE o.id_city = ${city_id} AND f.year = ${year}
ORDER BY f.year
OFFSET ${Number(offset) || 0} ROWS
FETCH NEXT ${Number(limit) || 10} ROWS ONLY;
`)
return result
}
async getLines(year: number, city_id: number): Promise<any[]> {
const result = await this.emsDataSource.query(
`
SELECT * FROM New_Gis..lines l
JOIN nGeneral..vObjects o ON l.object_id = o.object_id WHERE o.id_city = ${city_id} AND l.year = ${year};
`
)
return result
}
async getRegionBorders(): Promise<any[]> {
const result = await this.emsDataSource.query(
`
SELECT * FROM New_Gis..visual_regions
`
)
return result
}
}