Use correct country name in component title

This commit is contained in:
nymkappa 2022-07-16 23:25:44 +02:00
parent b11fb44461
commit 0902015264
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04
2 changed files with 20 additions and 7 deletions

View File

@ -1,6 +1,8 @@
import config from '../../config'; import config from '../../config';
import { Application, Request, Response } from 'express'; import { Application, Request, Response } from 'express';
import nodesApi from './nodes.api'; import nodesApi from './nodes.api';
import DB from '../../database';
class NodesRoutes { class NodesRoutes {
constructor() { } constructor() { }
@ -73,11 +75,22 @@ class NodesRoutes {
private async $getNodesPerCountry(req: Request, res: Response) { private async $getNodesPerCountry(req: Request, res: Response) {
try { 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()); const nodes = await nodesApi.$getNodesPerCountry(req.params.country.toLowerCase());
res.header('Pragma', 'public'); res.header('Pragma', 'public');
res.header('Cache-control', 'public'); res.header('Cache-control', 'public');
res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString()); 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) { } catch (e) {
res.status(500).send(e instanceof Error ? e.message : e); res.status(500).send(e instanceof Error ? e.message : e);
} }

View File

@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { map, Observable } from 'rxjs'; import { map, Observable } from 'rxjs';
import { ApiService } from 'src/app/services/api.service'; import { ApiService } from 'src/app/services/api.service';
import { SeoService } from 'src/app/services/seo.service';
@Component({ @Component({
selector: 'app-nodes-per-country', selector: 'app-nodes-per-country',
@ -15,18 +16,17 @@ export class NodesPerCountry implements OnInit {
constructor( constructor(
private apiService: ApiService, private apiService: ApiService,
private seoService: SeoService,
private route: ActivatedRoute, private route: ActivatedRoute,
) { } ) { }
ngOnInit(): void { 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) this.nodes$ = this.apiService.getNodeForCountry$(this.route.snapshot.params.country)
.pipe( .pipe(
map(nodes => { map(response => {
console.log(nodes); this.country = response.country.en
return nodes; this.seoService.setTitle($localize`Lightning nodes in ${this.country}`);
return response.nodes;
}) })
); );
} }