-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7901b6f
commit 9f28f4e
Showing
4 changed files
with
107 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import axios from 'axios' | ||
import logger from '../utils/logger.js' | ||
|
||
const datasetteUrl = 'https://datasette.planning.data.gov.uk' | ||
const database = 'digital-land' | ||
|
||
export default { | ||
runQuery: async (query) => { | ||
const encodedQuery = encodeURIComponent(query) | ||
const url = `${datasetteUrl}/${database}.json?sql=${encodedQuery}` | ||
try { | ||
const response = await axios.get(url) | ||
return response.data | ||
} catch (error) { | ||
logger.error(error) | ||
throw error | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,86 @@ | ||
import datasette from './datasette.js' | ||
|
||
/* | ||
*/ | ||
|
||
export default { | ||
getLpaOverview: async (lpa) => { | ||
getLpaOverviewOld: async (lpa) => { | ||
return { | ||
data: { | ||
name: 'Borechester City Council', | ||
datasets: { | ||
'article-4-direction': { | ||
endpoint: null | ||
}, | ||
'article-4-direction-area': { | ||
endpoint: null | ||
}, | ||
'conservation-area': { | ||
endpoint: 'http://conservation-area.json', | ||
error: null, | ||
issue: 'Endpoint has not been updated since 21 May 2023' | ||
}, | ||
'conservation-area-document': { | ||
endpoint: 'http://conservation-area-document.json', | ||
error: null, | ||
issue: null | ||
}, | ||
'listed-building-outline': { | ||
endpoint: 'http://listed-building-outline.json', | ||
error: null, | ||
issue: null | ||
}, | ||
tree: { | ||
endpoint: 'http://tree.json', | ||
error: null, | ||
issue: 'There are 20 issues in this dataset' | ||
}, | ||
'tree-preservation-order': { | ||
endpoint: 'http://tree-preservation-order.json', | ||
error: 'Error connecting to endpoint', | ||
issue: null | ||
}, | ||
'tree-preservation-zone': { | ||
endpoint: 'http://tree-preservation-zone.json', | ||
error: 'Error connecting to endpoint', | ||
issue: null | ||
} | ||
name: 'Borechester City Council', | ||
datasets: { | ||
'article-4-direction': { | ||
endpoint: null | ||
}, | ||
'article-4-direction-area': { | ||
endpoint: null | ||
}, | ||
'conservation-area': { | ||
endpoint: 'http://conservation-area.json', | ||
error: null, | ||
issue: 'Endpoint has not been updated since 21 May 2023' | ||
}, | ||
'conservation-area-document': { | ||
endpoint: 'http://conservation-area-document.json', | ||
error: null, | ||
issue: null | ||
}, | ||
'listed-building-outline': { | ||
endpoint: 'http://listed-building-outline.json', | ||
error: null, | ||
issue: null | ||
}, | ||
tree: { | ||
endpoint: 'http://tree.json', | ||
error: null, | ||
issue: 'There are 20 issues in this dataset' | ||
}, | ||
'tree-preservation-order': { | ||
endpoint: 'http://tree-preservation-order.json', | ||
error: 'Error connecting to endpoint', | ||
issue: null | ||
}, | ||
'tree-preservation-zone': { | ||
endpoint: 'http://tree-preservation-zone.json', | ||
error: 'Error connecting to endpoint', | ||
issue: null | ||
} | ||
} | ||
} | ||
}, | ||
|
||
getLpaOverview: async (lpa) => { | ||
const query = | ||
`SELECT | ||
p.organisation, | ||
o.name, | ||
p.dataset, | ||
rle.endpoint | ||
FROM | ||
provision p | ||
INNER JOIN | ||
organisation o ON o.organisation = p.organisation | ||
LEFT JOIN | ||
reporting_latest_endpoints rle | ||
ON REPLACE(rle.organisation, '-eng', '') = p.organisation | ||
AND rle.pipeline = p.dataset | ||
WHERE p.organisation = '${lpa}' | ||
ORDER BY | ||
p.organisation, | ||
o.name` | ||
|
||
const result = await datasette.runQuery(query) | ||
|
||
const datasets = result.rows.reduce((accumulator, row) => { | ||
accumulator[row[2]] = { | ||
endpoint: row[3] | ||
} | ||
return accumulator | ||
}, {}) | ||
|
||
return { | ||
name: result.rows[0][1], | ||
datasets | ||
} | ||
} | ||
} |