Make new route in api instead of going through npm script; new retrieveAll call for controller

This commit is contained in:
efarooqui
2021-02-08 11:49:43 -08:00
parent d6d565a0fc
commit 7bafcb0343
4 changed files with 39 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
"version": "0.3.0",
"description": "Starter project for an ES6 RESTful Express API",
"main": "dist",
"type": "module",
"scripts": {
"dev": "env NODE_ENV=development nodemon -w src --exec \"babel-node src\"",
"build": "env NODE_ENV=production npx babel src -d dist",
@@ -26,6 +27,7 @@
"express": "^4.13.3",
"express-graphql": "^0.6.12",
"express-handlebars": "^4.0.4",
"file-system": "^2.2.2",
"googleapis": "^39.1.0",
"graphql": "^0.13.2",
"morgan": "^1.8.0",

View File

@@ -1,5 +1,6 @@
import { version } from '../../package.json'
import { Router } from 'express'
import { exportToFile } from '../utilities'
import copy from '../copy/en'
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) => {
controller
.update()

View File

@@ -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) {
if (this._sheetExists(sheet)) {
const fetcher = this.fetchers[sheet]

11
src/utilities.js Normal file
View 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
}