Fix api units
parent
06eb426316
commit
68d6e1cd2c
|
@ -13,6 +13,7 @@ import { redisCacheMiddleware } from './redis-cache.js'
|
|||
import { docRoutes } from './route/doc.js'
|
||||
import { openapiRoutes } from './route/openapi.js'
|
||||
import Sentry, { requestHandler, tracingMiddleWare } from './sentry.js'
|
||||
import { getUnitKey } from './units.js'
|
||||
|
||||
type State = Koa.DefaultState
|
||||
type Context = Koa.DefaultContext
|
||||
|
@ -42,7 +43,7 @@ app.use(cors())
|
|||
|
||||
router.use('/api/v1', docRoutes(), openapiRoutes(openapi))
|
||||
|
||||
const apiRoutes = publicodesAPI(new Engine(rules))
|
||||
const apiRoutes = publicodesAPI(new Engine(rules, { getUnitKey }))
|
||||
|
||||
router.use(
|
||||
'/api/v1',
|
||||
|
@ -65,4 +66,4 @@ const server = app.listen(port, function () {
|
|||
console.log('listening on port:', port)
|
||||
})
|
||||
|
||||
export { server, app }
|
||||
export { app, server }
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// units from site/source/locales/units.yaml:
|
||||
const units = Object.entries({
|
||||
heure_plural: 'heures',
|
||||
jour_plural: 'jours',
|
||||
'jour ouvré_plural': 'jours ouvrés',
|
||||
semaine_plural: 'semaine',
|
||||
trimestre_plural: 'trimestres',
|
||||
'trimestre validé_plural': 'trimestres validés',
|
||||
an_plural: 'ans',
|
||||
employé_plural: 'employés',
|
||||
point_plural: 'points',
|
||||
mois_plural: 'mois',
|
||||
manifestation_plural: 'manifestations',
|
||||
'titre-restaurant_plural': 'titres-restaurant',
|
||||
part_plural: 'parts',
|
||||
enfant_plural: 'enfants',
|
||||
})
|
||||
|
||||
export const getUnitKey = (unit: string): string => {
|
||||
const key = units
|
||||
.find(([, trans]) => trans === unit)?.[0]
|
||||
.replace(/_plural$/, '')
|
||||
|
||||
return key || unit
|
||||
}
|
Loading…
Reference in New Issue