diff --git a/backend/src/api/explorer/nodes.routes.ts b/backend/src/api/explorer/nodes.routes.ts index 07986f0b1..4bdd73f79 100644 --- a/backend/src/api/explorer/nodes.routes.ts +++ b/backend/src/api/explorer/nodes.routes.ts @@ -1,6 +1,8 @@ import config from '../../config'; import { Application, Request, Response } from 'express'; import nodesApi from './nodes.api'; +import DB from '../../database'; + class NodesRoutes { constructor() { } @@ -73,11 +75,22 @@ class NodesRoutes { private async $getNodesPerCountry(req: Request, res: Response) { try { + const [countryName]: any[] = await DB.query(`SELECT names FROM geo_names WHERE LOWER(JSON_EXTRACT(geo_names.names, '$.en')) = ?`, + [`"${req.params.country}"`]); + + if (countryName.length === 0) { + res.status(404).send(`This country does not exists`); + return; + } + const nodes = await nodesApi.$getNodesPerCountry(req.params.country.toLowerCase()); res.header('Pragma', 'public'); res.header('Cache-control', 'public'); res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString()); - res.json(nodes); + res.json({ + country: JSON.parse(countryName[0].names), + nodes: nodes, + }); } catch (e) { res.status(500).send(e instanceof Error ? e.message : e); } diff --git a/frontend/src/app/lightning/nodes-per-country/nodes-per-country.component.ts b/frontend/src/app/lightning/nodes-per-country/nodes-per-country.component.ts index db9bc5809..e353d1361 100644 --- a/frontend/src/app/lightning/nodes-per-country/nodes-per-country.component.ts +++ b/frontend/src/app/lightning/nodes-per-country/nodes-per-country.component.ts @@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core import { ActivatedRoute } from '@angular/router'; import { map, Observable } from 'rxjs'; import { ApiService } from 'src/app/services/api.service'; +import { SeoService } from 'src/app/services/seo.service'; @Component({ selector: 'app-nodes-per-country', @@ -15,18 +16,17 @@ export class NodesPerCountry implements OnInit { constructor( private apiService: ApiService, + private seoService: SeoService, private route: ActivatedRoute, ) { } ngOnInit(): void { - this.country = this.route.snapshot.params.country; - this.country = this.country.charAt(0).toUpperCase() + this.country.slice(1); - this.nodes$ = this.apiService.getNodeForCountry$(this.route.snapshot.params.country) .pipe( - map(nodes => { - console.log(nodes); - return nodes; + map(response => { + this.country = response.country.en + this.seoService.setTitle($localize`Lightning nodes in ${this.country}`); + return response.nodes; }) ); }