Files
shields/services/wheelmap/wheelmap.service.js
T
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>chris48s
b9d96755ec chore(deps-dev): bump prettier from 2.8.8 to 3.0.0 (#9357)
* chore(deps-dev): bump prettier from 2.8.8 to 3.0.0

Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.0.0)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* reformat all the things (prettier 3)

* update tests to await calls to prettier.format()

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: chris48s <git@chris-shaw.dev>
2023-07-10 09:27:51 +00:00

68 lines
1.5 KiB
JavaScript

import Joi from 'joi'
import { BaseJsonService } from '../index.js'
const schema = Joi.object({
node: Joi.object({
wheelchair: Joi.string().required(),
}).required(),
}).required()
export default class Wheelmap extends BaseJsonService {
static category = 'other'
static route = {
base: 'wheelmap/a',
pattern: ':nodeId(-?[0-9]+)',
}
static auth = {
passKey: 'wheelmap_token',
authorizedOrigins: ['https://wheelmap.org'],
isRequired: true,
}
static examples = [
{
title: 'Wheelmap',
namedParams: { nodeId: '26699541' },
staticPreview: this.render({ accessibility: 'yes' }),
},
]
static defaultBadgeData = { label: 'accessibility' }
static render({ accessibility }) {
let color
if (accessibility === 'yes') {
color = 'brightgreen'
} else if (accessibility === 'limited') {
color = 'yellow'
} else if (accessibility === 'no') {
color = 'red'
}
return { message: accessibility, color }
}
async fetch({ nodeId }) {
return this._requestJson(
this.authHelper.withQueryStringAuth(
{ passKey: 'api_key' },
{
schema,
url: `https://wheelmap.org/api/nodes/${nodeId}`,
httpErrors: {
401: 'invalid token',
404: 'node not found',
},
},
),
)
}
async handle({ nodeId }) {
const json = await this.fetch({ nodeId })
const accessibility = json.node.wheelchair
return this.constructor.render({ accessibility })
}
}