Skip to content

Commit

Permalink
fix Typescript delete must be on optional error (#89)
Browse files Browse the repository at this point in the history
* fix Typescript delete must be on optional error

* don't query dummy stop_lat and stop_lon

* combine Object.assign with spread operation

* Revert "combine Object.assign with spread operation"

This reverts commit ec5c765.

---------

Co-authored-by: Michael Tsang <michael.tsang@jnction.co.uk>
  • Loading branch information
miklcct and Michael Tsang committed May 3, 2024
1 parent 6dc5661 commit da2ddda
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/gtfs/repository/CIFRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ export class CIFRepository {
* Return all the stops with some configurable long/lat applied
*/
public async getStops(): Promise<Stop[]> {
const [results] = await this.db.query<(Stop & {easting : number, northing : number})>(`
const [results] = await this.db.query<Omit<Stop, 'stop_lat' | 'stop_lon'> & {easting : number, northing : number}>(`
SELECT
crs_code AS stop_id,
tiploc_code AS stop_code,
station_name AS stop_name,
cate_interchange_status AS stop_desc,
0 AS stop_lat,
0 AS stop_lon,
NULL AS zone_id,
NULL AS stop_url,
NULL AS location_type,
Expand All @@ -67,12 +65,9 @@ export class CIFRepository {
`);

// overlay the long and latitude values from configuration
return results.map(stop => {
const [stop_lon, stop_lat] = proj4('EPSG:27700', 'EPSG:4326', [(stop.easting - 10000) * 100, (stop.northing - 60000) * 100]);
stop.stop_lon = stop_lon;
stop.stop_lat = stop_lat;
delete stop.easting;
delete stop.northing;
return results.map(row => {
const [stop_lon, stop_lat] = proj4('EPSG:27700', 'EPSG:4326', [(row.easting - 10000) * 100, (row.northing - 60000) * 100]);
const {easting, northing, ...stop} = {...row, stop_lon, stop_lat};
return Object.assign(stop, this.stationCoordinates[stop.stop_id]);
});
}
Expand Down

0 comments on commit da2ddda

Please sign in to comment.