Skip to content

Commit

Permalink
chore: slugify presets for comparing and default lang to en
Browse files Browse the repository at this point in the history
  • Loading branch information
luandro committed Feb 6, 2025
1 parent e23b43d commit 573fa52
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
56 changes: 56 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"@fastify/websocket": "^10.0.1",
"@mapeo/crypto": "^1.0.0-alpha.10",
"@sinclair/typebox": "^0.34.15",
"@sindresorhus/slugify": "^2.2.1",
"@types/qrcode": "^1.5.5",
"env-schema": "^6.0.1",
"fastify": "^4.29.0",
Expand Down
9 changes: 7 additions & 2 deletions src/routes/observations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Type } from '@sinclair/typebox'
import slugify from '@sindresorhus/slugify'

import * as errors from '../errors.js'
import * as schemas from '../schemas.js'
Expand Down Expand Up @@ -106,8 +107,12 @@ export default async function observationRoutes(

let preset
if (category) {
const presets = await project.preset.getMany({ lang: locale })
preset = presets.find((p) => p.name === category)
const presets = await project.preset.getMany({ lang: locale || 'en' })
preset = presets.find(
(p) =>
slugify(p.name, { lowercase: true }) ===
slugify(category, { lowercase: true }),
)
if (!preset) {
throw errors.badRequestError(`Category "${category}" not found`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default async function projectsRoutes(fastify, opts) {
}
const presets = locale
? await project.preset.getMany({ lang: locale })
: await project.preset.getMany({ lang: locale })
: await project.preset.getMany()
const fields = await project.field.getMany()

// Create a map of field docIds to field objects for quick lookup
Expand Down

0 comments on commit 573fa52

Please sign in to comment.