Skip to content

Commit

Permalink
Meta-linted
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Sep 1, 2021
1 parent 3f2968a commit 412087a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/http/get-login/github.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/http/get-login/index.js
Original file line number Diff line number Diff line change
@@ -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: '/'
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/post-graphql/middleware/auth.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/http/post-graphql/middleware/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ 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 }
}
})

/** 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 }
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/http/post-graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ 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
delete copy.token
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}`)
Expand All @@ -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
})
}
2 changes: 1 addition & 1 deletion src/http/post-logout/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let arc = require('@architect/functions')

async function logout(req) {
async function logout () {
return {
session: {},
location: '/'
Expand Down

0 comments on commit 412087a

Please sign in to comment.