Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

Commit

Permalink
Refactoring (patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed Jan 6, 2017
1 parent 86f363d commit 4afb111
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 2 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { parse } = require('url')
const { json, send } = require('micro')
const listAllRoles = require('./lib/list-all-roles')
const filterRoles = require('./lib/filter-roles')
const generateId = require('./lib/generate-id')
const idFromInput = require('./lib/id-from-input')

module.exports = async (request, response) => {
const {pathname, query} = await parse(request.url, true)
Expand All @@ -15,11 +15,7 @@ module.exports = async (request, response) => {
if (pathname === '/roles') {
send(response, 200, Object.values(data).length > 0 ? filterRoles(data) : listAllRoles())
} else if (pathname === '/id') {
const result = {
input: data.input || '',
generatedId: generateId(data.input || '')
}
send(response, 200, result)
send(response, 200, idFromInput(data))
} else {
const readme = readFileSync('./README.md', 'utf-8')
const html = marked(readme)
Expand Down
10 changes: 10 additions & 0 deletions lib/id-from-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const generateId = require('./generate-id')

module.exports = (data) => {
return {
input: data.input || '',
generatedId: generateId(data.input || '')
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "micro-tfk-roles",
"description": "Mapping of roles",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"author": {
"name": "Geir Gåsodden",
Expand Down

0 comments on commit 4afb111

Please sign in to comment.