Skip to content

Commit

Permalink
add function documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamez committed Jan 26, 2024
1 parent bebd101 commit 5f6ab4d
Showing 1 changed file with 55 additions and 24 deletions.
79 changes: 55 additions & 24 deletions functions/validator-summary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
const GBFS = require('gbfs-validator')

/** @typedef {{
* summary: {
* validatorVersion: string,
* hasErrors: boolean,
* errorsCount: number,
* version: {
* detected: string,
* validated: string
* }
* filesSummary: [
* {
* required: boolean,
* exists: boolean,
* hasErrors: boolean,
* file: string,
* errorsCount: number
* }
* ]
* }
* }} Summary
*/

/**
* This function returns a summary from the validator's response stripping out the notices.
*
* @param validationResult from the GBFS validator class
* @returns { Summary }
*/
const getSummary = (validationResult) => (
{
...validationResult,
Expand All @@ -14,32 +42,35 @@ const getSummary = (validationResult) => (
}
)

exports.handler = function (event, context, callback) {
let body
/**
* call the callback function with {@link Summary}
*/
exports.handler = function (event, context, callback) {
let body

try {
body = JSON.parse(event.body)
} catch (err) {
callback(err, {
statusCode: 500,
body: JSON.stringify(err)
})
}
try {
body = JSON.parse(event.body)
} catch (err) {
callback(err, {
statusCode: 500,
body: JSON.stringify(err)
})
}

const gbfs = new GBFS(body.url, body.options)
const gbfs = new GBFS(body.url, body.options)

gbfs
.validation()
.then(result => {
callback(null, {
statusCode: 200,
body: JSON.stringify(getSummary(result))
gbfs
.validation()
.then(result => {
callback(null, {
statusCode: 200,
body: JSON.stringify(getSummary(result))
})
})
})
.catch(err => {
callback(null, {
statusCode: 500,
body: JSON.stringify(err.message)
.catch(err => {
callback(null, {
statusCode: 500,
body: JSON.stringify(err.message)
})
})
})
}
}

0 comments on commit 5f6ab4d

Please sign in to comment.