Skip to content

Commit

Permalink
map: fetches geometries from API
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgnlez committed Oct 28, 2024
1 parent b1db730 commit 490fac5
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 332 deletions.
1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@nestjs/testing": "^10.0.0",
"@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.17",
"@types/geojson": "catalog:",
"@types/jest": "^29.5.12",
"@types/jsonapi-serializer": "^3.6.8",
"@types/lodash": "^4.17.7",
Expand Down
19 changes: 13 additions & 6 deletions api/src/modules/countries/map/map.repository.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
import { FeatureCollection, Repository } from 'typeorm';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Country } from '@shared/entities/country.entity';
import { BaseData } from '@shared/entities/base-data.entity';

import { FeatureCollection, Geometry } from 'geojson';

import { ProjectGeoProperties } from '@shared/schemas/geometries/projects';

/**
* @description: The aim for this repository is to work with geospatial data, for now "geometry" column in countries
* table. The country repository will be used to work with the metadata of the countries and avoid loading geometries when only metadata is needed,
Expand All @@ -22,7 +26,7 @@ export class MapRepository extends Repository<Country> {

async getGeoFeatures(
countryCode: Country['code'],
): Promise<FeatureCollection> {
): Promise<FeatureCollection<Geometry, ProjectGeoProperties>> {
const queryBuilder = this.createQueryBuilder('country');
queryBuilder.innerJoin(BaseData, 'bd', 'bd.country_code = country.code');
queryBuilder.select(
Expand All @@ -45,10 +49,13 @@ export class MapRepository extends Repository<Country> {
});
}

const result: { geojson: FeatureCollection } | undefined =
await queryBuilder.getRawOne<{
geojson: FeatureCollection;
}>();
const result:
| {
geojson: FeatureCollection<Geometry, ProjectGeoProperties>;
}
| undefined = await queryBuilder.getRawOne<{
geojson: FeatureCollection<Geometry, ProjectGeoProperties>;
}>();
this.logger.log(`Retrieved geo features`);
if (!result) {
throw new NotFoundException(`Could not retrieve geo features`);
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"devDependencies": {
"@types/d3": "7.4.3",
"@types/geojson": "7946.0.14",
"@types/geojson": "catalog:",
"@types/mapbox-gl": "3.4.0",
"@types/node": "catalog:",
"@types/react": "^18",
Expand Down
11 changes: 10 additions & 1 deletion client/src/app/(projects)/url-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { parseAsJson, parseAsStringLiteral, useQueryState } from "nuqs";
import {
parseAsJson,
parseAsString,
parseAsStringLiteral,
useQueryState,
} from "nuqs";
import { z } from "zod";

import {
Expand Down Expand Up @@ -29,6 +34,10 @@ export function useGlobalFilters() {
);
}

export function useSyncCountry() {
return useQueryState("country", parseAsString.withDefault(""));
}

export function useTableMode() {
return useQueryState(
"table",
Expand Down
Loading

0 comments on commit 490fac5

Please sign in to comment.