mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-12 13:28:32 +03:00
Make new route in api instead of going through npm script; new retrieveAll call for controller
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"description": "Starter project for an ES6 RESTful Express API",
|
"description": "Starter project for an ES6 RESTful Express API",
|
||||||
"main": "dist",
|
"main": "dist",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "env NODE_ENV=development nodemon -w src --exec \"babel-node src\"",
|
"dev": "env NODE_ENV=development nodemon -w src --exec \"babel-node src\"",
|
||||||
"build": "env NODE_ENV=production npx babel src -d dist",
|
"build": "env NODE_ENV=production npx babel src -d dist",
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
"express": "^4.13.3",
|
"express": "^4.13.3",
|
||||||
"express-graphql": "^0.6.12",
|
"express-graphql": "^0.6.12",
|
||||||
"express-handlebars": "^4.0.4",
|
"express-handlebars": "^4.0.4",
|
||||||
|
"file-system": "^2.2.2",
|
||||||
"googleapis": "^39.1.0",
|
"googleapis": "^39.1.0",
|
||||||
"graphql": "^0.13.2",
|
"graphql": "^0.13.2",
|
||||||
"morgan": "^1.8.0",
|
"morgan": "^1.8.0",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { version } from '../../package.json'
|
import { version } from '../../package.json'
|
||||||
import { Router } from 'express'
|
import { Router } from 'express'
|
||||||
|
import { exportToFile } from '../utilities'
|
||||||
import copy from '../copy/en'
|
import copy from '../copy/en'
|
||||||
|
|
||||||
export default ({ config, controller }) => {
|
export default ({ config, controller }) => {
|
||||||
@@ -22,6 +23,27 @@ export default ({ config, controller }) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
api.get('/export', (req, res) => {
|
||||||
|
const bps = controller.blueprints()
|
||||||
|
const bpsParsed = bps.map(bp => ({
|
||||||
|
sheet: bp.sheet.name,
|
||||||
|
tab: bp.name,
|
||||||
|
resources: bp.resources,
|
||||||
|
url: bp.urls[0]
|
||||||
|
}))
|
||||||
|
controller
|
||||||
|
.retrieveAll(bpsParsed)
|
||||||
|
.then(msg =>
|
||||||
|
res.json({
|
||||||
|
success: msg
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.catch(err =>
|
||||||
|
res.status(404)
|
||||||
|
.send({ error: err.message, err })
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
api.get('/update', (req, res) => {
|
api.get('/update', (req, res) => {
|
||||||
controller
|
controller
|
||||||
.update()
|
.update()
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ class Controller {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retrieveAll (blueprints) {
|
||||||
|
// index through bps, grab data and add to existing data object with value for url name and data points for data object, write to file and return success msg; catch errors appropriately
|
||||||
|
}
|
||||||
|
|
||||||
retrieve (sheet, tab, resource) {
|
retrieve (sheet, tab, resource) {
|
||||||
if (this._sheetExists(sheet)) {
|
if (this._sheetExists(sheet)) {
|
||||||
const fetcher = this.fetchers[sheet]
|
const fetcher = this.fetchers[sheet]
|
||||||
|
|||||||
11
src/utilities.js
Normal file
11
src/utilities.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import fs from 'file-system'
|
||||||
|
|
||||||
|
function exportToFile(url, data) {
|
||||||
|
console.info(url, data)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
export const utilities = {
|
||||||
|
default: exportToFile(),
|
||||||
|
exportToFile
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user