Überarbeitung

This commit is contained in:
2024-08-09 17:59:49 +02:00
parent 6d1c50d5df
commit 1e1d5cea57
27 changed files with 135 additions and 112 deletions

View File

@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { readFileSync } from 'fs';
import path, { join } from 'path';
import { CountyResult, GeoResult } from 'src/models/main.model.js';
import { CityAndStateResult, CountyResult, GeoResult } from 'src/models/main.model.js';
import { fileURLToPath } from 'url';
import { City, CountyData, Geo, State } from '../models/server.model.js';
@@ -52,7 +52,7 @@ export class GeoService {
if (city.name.toLowerCase().startsWith(prefix.toLowerCase())) {
result.push({
id: city.id,
city: city.name,
name: city.name,
state: state.state_code,
//state_code: state.state_code,
latitude: city.latitude,
@@ -63,8 +63,8 @@ export class GeoService {
});
return state ? result.filter(e => e.state.toLowerCase() === state.toLowerCase()) : result;
}
findCitiesAndStatesStartingWith(prefix: string, state?: string): Array<{ id: string; name: string; type: 'city' | 'state'; state: string }> {
const results: Array<{ id: string; name: string; type: 'city' | 'state'; state: string }> = [];
findCitiesAndStatesStartingWith(prefix: string, state?: string): Array<CityAndStateResult> {
const results: Array<CityAndStateResult> = [];
const lowercasePrefix = prefix.toLowerCase();
@@ -73,10 +73,9 @@ export class GeoService {
for (const state of this.geo.states) {
if (state.name.toLowerCase().startsWith(lowercasePrefix)) {
results.push({
id: state.id.toString(),
name: state.name,
id: state.id,
type: 'state',
state: state.state_code,
content: state,
});
}
@@ -84,10 +83,9 @@ export class GeoService {
for (const city of state.cities) {
if (city.name.toLowerCase().startsWith(lowercasePrefix)) {
results.push({
id: city.id.toString(),
name: city.name,
id: city.id,
type: 'city',
state: state.state_code,
content: { state: state.state_code, ...city },
});
}
}
@@ -97,7 +95,7 @@ export class GeoService {
return results.sort((a, b) => {
if (a.type === 'state' && b.type === 'city') return -1;
if (a.type === 'city' && b.type === 'state') return 1;
return a.name.localeCompare(b.name);
return a.content.name.localeCompare(b.content.name);
});
}
getCityWithCoords(state: string, city: string): City {