Get nodes per country list with /lightning/nodes/country/:country API

This commit is contained in:
nymkappa
2022-07-13 00:25:40 +02:00
parent 561d75c694
commit fc5fd244d0
2 changed files with 28 additions and 0 deletions

View File

@@ -124,6 +124,21 @@ class NodesApi {
throw e;
}
}
public async $getNodesPerCountry(country: string) {
try {
const query = `SELECT nodes.* FROM nodes
JOIN geo_names ON geo_names.id = nodes.country_id
WHERE LOWER(json_extract(names, '$.en')) = ?
`;
const [rows]: any = await DB.query(query, [`"${country}"`]);
return rows;
} catch (e) {
logger.err(`Cannot get nodes for country ${country}. Reason: ${e instanceof Error ? e.message : e}`);
throw e;
}
}
}
export default new NodesApi();