Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
fix: use strict
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangoacher committed Feb 24, 2020
1 parent 861bc15 commit fb67c49
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 13 deletions.
5 changes: 2 additions & 3 deletions packages/trail-fastify-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ npm install @nearform/trail-fastify-plugin
## Usage

```javascript
const Fastify = require('fastify')

const main = async function() {
import Fastify from 'fastify'
const fastify = Fastify()

fastify.register(require('@nearform/trail-fastify-plugin'))

await fastify.ready()

await fastify.listen(3000, console.log)
}

Expand Down
2 changes: 2 additions & 0 deletions packages/trail-fastify-plugin/lib/api.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const { get } = require('lodash')

const addReference = function (spec) {
Expand Down
5 changes: 3 additions & 2 deletions packages/trail-fastify-plugin/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const fp = require('fastify-plugin')
const { TrailsManager } = require('@nearform/trail-core')
const { get } = require('lodash')
Expand Down Expand Up @@ -72,9 +74,8 @@ async function trail (server, options) {
server.decorate('trailCore', trailsManager)
server.decorateReply('trailCore', trailsManager)

server.addHook('onClose', async (instance, done) => {
server.addHook('onClose', async instance => {
await trailsManager.close()
done()
})

const ajv = new Ajv({ allErrors: true })
Expand Down
18 changes: 10 additions & 8 deletions packages/trail-fastify-plugin/lib/routes/trails.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict'

const { notFound } = require('@hapi/boom')
const S = require('fluent-schema')

const { errorsSchemas } = require('../schemas/errors')
const { spec, trailSchema } = require('../schemas/trails')
const { addApiRoute, generateSpec } = require('../api')

module.exports = async function (fastify, options, done) {
module.exports = async function (fastify, options) {
for (const path of ['/trails/openapi.json', '/trails/swagger.json']) {
fastify.route({
method: 'GET',
Expand All @@ -22,7 +24,7 @@ module.exports = async function (fastify, options, done) {
async handler (request, reply) {
const { from, to, who, what, subject, page, pageSize, sort } = request.query
const results = await reply.trailCore.search({ from, to, who, what, subject, page, pageSize, sort })
reply.send(results)
return results
},
schema: {
query: trailSchema.search,
Expand All @@ -46,7 +48,7 @@ module.exports = async function (fastify, options, done) {
async handler (request, reply) {
const { from, to, type, page, pageSize, desc } = request.query
const results = await reply.trailCore.enumerate({ from, to, type, page, pageSize, desc })
reply.send(results)
return results
},
schema: {
query: trailSchema.enumerate,
Expand All @@ -70,7 +72,8 @@ module.exports = async function (fastify, options, done) {
async handler (request, reply) {
const id = await reply.trailCore.insert(request.body)
const trail = await reply.trailCore.get(id)
reply.code(201).send(trail)
reply.code(201)
return trail
},
schema: {
headers: S.object()
Expand Down Expand Up @@ -99,7 +102,7 @@ module.exports = async function (fastify, options, done) {

if (!trail) throw notFound(`Trail with id ${id} not found.`)

return reply.send(trail)
return trail
},
schema: {
params: trailSchema.params,
Expand Down Expand Up @@ -127,7 +130,8 @@ module.exports = async function (fastify, options, done) {
if (!updated) throw notFound(`Trail with id ${id} not found.`)

const trail = await reply.trailCore.get(id)
reply.code(202).send(trail)
reply.code(202)
return trail
},
schema: {
headers: S.object()
Expand Down Expand Up @@ -179,6 +183,4 @@ module.exports = async function (fastify, options, done) {

// Add tagged routes to the swagger.json
generateSpec(spec, 'trails')

done()
}
2 changes: 2 additions & 0 deletions packages/trail-fastify-plugin/lib/schemas/errors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const S = require('fluent-schema')

const errorsMessages = {
Expand Down
2 changes: 2 additions & 0 deletions packages/trail-fastify-plugin/lib/schemas/trails.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const config = require('config')
const S = require('fluent-schema')

Expand Down
2 changes: 2 additions & 0 deletions packages/trail-fastify-server/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const S = require('fluent-schema')
const fastify = require('fastify')
const config = require('config')
Expand Down
2 changes: 2 additions & 0 deletions packages/trail-fastify-server/lib/swagger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const { readFile } = require('fs').promises
const { extname, join } = require('path')

Expand Down
2 changes: 2 additions & 0 deletions packages/trail-fastify-server/start.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

// If forked as child, send output message via ipc to parent, otherwise output to console
const logMessage = process.send ? process.send : console.log

Expand Down
2 changes: 2 additions & 0 deletions packages/trail-hapi-plugin/lib/api.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const { get } = require('lodash')
const j2s = require('joi-to-swagger')

Expand Down
2 changes: 2 additions & 0 deletions packages/trail-hapi-plugin/lib/schemas/trails.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const config = require('config')
const Joi = require('@hapi/joi')
const j2s = require('joi-to-swagger')
Expand Down
2 changes: 2 additions & 0 deletions packages/trail-hapi-server/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const Joi = require('@hapi/joi')
const config = require('config')
const { errorsSchemas } = require('@nearform/trail-hapi-plugin/lib/schemas/errors')
Expand Down
2 changes: 2 additions & 0 deletions packages/trail-hapi-server/lib/swagger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const { readFileSync } = require('fs')
const { join } = require('path')

Expand Down

0 comments on commit fb67c49

Please sign in to comment.