diff --git a/src/http/get-login/github.js b/src/http/get-login/github.js index cb3ddd8..09bec78 100644 --- a/src/http/get-login/github.js +++ b/src/http/get-login/github.js @@ -1,11 +1,11 @@ let tiny = require('tiny-json-http') -module.exports = async function github(req) { +module.exports = async function github (req) { // trade the code for an access token let result = await tiny.post({ url: 'https://github.com/login/oauth/access_token', - headers: {Accept: 'application/json'}, + headers: { accept: 'application/json' }, data: { code: req.query.code, client_id: process.env.GITHUB_CLIENT_ID, @@ -19,7 +19,7 @@ module.exports = async function github(req) { // use the access token to get the user account let user = await tiny.get({ url: `https://api.github.com/user?access_token=${token}`, - headers: {Accept: 'application/json'}, + headers: { accept: 'application/json' }, }) // create a clean acccount obj diff --git a/src/http/get-login/index.js b/src/http/get-login/index.js index 9d8e83a..da0ba03 100644 --- a/src/http/get-login/index.js +++ b/src/http/get-login/index.js @@ -1,11 +1,11 @@ let arc = require('@architect/functions') let github = require('./github') -async function login(req) { +async function login (req) { if (req.query.code) { let account = await github(req) return { - session: {account}, + session: { account }, location: '/' } } diff --git a/src/http/post-graphql/middleware/auth.js b/src/http/post-graphql/middleware/auth.js index ae84038..87c1ce8 100644 --- a/src/http/post-graphql/middleware/auth.js +++ b/src/http/post-graphql/middleware/auth.js @@ -1,5 +1,5 @@ // mutations require req.session.account -module.exports = async function auth(req) { +module.exports = async function auth (req) { let client_id = process.env.GITHUB_CLIENT_ID let redirect_uri = process.env.GITHUB_REDIRECT diff --git a/src/http/post-graphql/middleware/query.js b/src/http/post-graphql/middleware/query.js index 2971137..d49ddcf 100644 --- a/src/http/post-graphql/middleware/query.js +++ b/src/http/post-graphql/middleware/query.js @@ -11,8 +11,8 @@ let { account, draft, drafts, save, destroy } = require('../resolvers') let typeDefs = fs.readFileSync(path.join(__dirname, '..', 'schema.graphql')).toString() // 3. combine resolvers and schema -let schema = makeExecutableSchema({ - typeDefs, +let schema = makeExecutableSchema({ + typeDefs, resolvers: { Query: { draft, drafts }, Mutation: { account, save, destroy } @@ -20,15 +20,15 @@ let schema = makeExecutableSchema({ }) /** graphql middleware */ -module.exports = async function query(req) { +module.exports = async function query (req) { try { - let result = await graphql(schema, req.body.query, {}, req.session, req.body.variables, req.body.operationName) - return { + let result = await graphql(schema, req.body.query, {}, req.session, req.body.variables, req.body.operationName) + return { json: result } } - catch(e) { - return { + catch (e) { + return { json: { error: e.name, message: e.message, stack: e.stack } } } diff --git a/src/http/post-graphql/resolvers.js b/src/http/post-graphql/resolvers.js index 68076a1..e0932e3 100644 --- a/src/http/post-graphql/resolvers.js +++ b/src/http/post-graphql/resolvers.js @@ -9,7 +9,7 @@ module.exports = { destroy } -async function account(root, args, session) { +async function account (root, args, session) { if (!session.account) throw Error('not authorized') let copy = session.account @@ -17,23 +17,23 @@ async function account(root, args, session) { return copy } -async function draft(root, args, session) { - return await data.get({ - table: 'drafts', +async function draft (root, args) { + return data.get({ + table: 'drafts', ...args }) } -async function drafts(root, args, session) { - return await data.get({ - table: 'drafts', +async function drafts () { + return data.get({ + table: 'drafts', }) } -async function save(root, draft, session) { +async function save (root, draft, session) { if (!session.account) throw Error('not authorized') - let required = ['title', 'body']//, 'author', 'avatar'] + let required = [ 'title', 'body' ]// , 'author', 'avatar'] for (let param of required) { if (!draft[param]) throw ReferenceError(`missing param ${param}`) @@ -44,17 +44,17 @@ async function save(root, draft, session) { draft.avatar = session.account.avatar draft.title = xss(draft.title) draft.body = xss(draft.body) - return await data.set({ - table: 'drafts', + return data.set({ + table: 'drafts', ...draft }) } -async function destroy(root, draft, session) { +async function destroy (root, draft, session) { if (!session.account) throw Error('not authorized') - return await data.destroy({ - table: 'drafts', + return data.destroy({ + table: 'drafts', ...draft }) } diff --git a/src/http/post-logout/index.js b/src/http/post-logout/index.js index 1413419..794d99d 100644 --- a/src/http/post-logout/index.js +++ b/src/http/post-logout/index.js @@ -1,6 +1,6 @@ let arc = require('@architect/functions') -async function logout(req) { +async function logout () { return { session: {}, location: '/'