Skip to content

Commit

Permalink
update: use publicodes 1.0.0-rc.3
Browse files Browse the repository at this point in the history
  • Loading branch information
johangirod committed Dec 20, 2023
1 parent ba33735 commit 94d56d1
Show file tree
Hide file tree
Showing 42 changed files with 1,964 additions and 833 deletions.
4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@apidevtools/swagger-cli": "^4.0.4",
"@koa/cors": "^4.0.0",
"@koa/router": "^12.0.0",
"@publicodes/rest-api": "^1.0.0-rfc.1",
"@publicodes/rest-api": "1.0.0-rc.4",
"@sentry/node": "^7.70.0",
"@sentry/utils": "^7.70.0",
"got": "^13.0.0",
Expand All @@ -43,7 +43,7 @@
"modele-social": "workspace:^",
"nodemon": "^3.0.1",
"piano-analytics-js": "^6.13.0",
"publicodes": "^1.0.0-rfc.1",
"publicodes": "1.0.0-rc.4",
"rate-limiter-flexible": "^2.4.2",
"swagger-ui-dist": "^5.7.2"
},
Expand Down
2 changes: 1 addition & 1 deletion api/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ router.use(
rateLimiterMiddleware,
redisCacheMiddleware(),
analyticsMiddleware,
v1unitéAdapterMiddleware,
v1unitéAdapterMiddleware(),
apiRoutes
)

Expand Down
4 changes: 2 additions & 2 deletions api/source/redis-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { koaBody } from 'koa-body'
const Redis = IORedis.default
const RedisMock = IORedisMock.default

// cache expires in 12 hours (in seconds)
const CACHE_EXPIRE = 12 * 60 * 60
// cache expires in 24 hours (in seconds)
const CACHE_EXPIRE = 24 * 60 * 60

const redis =
process.env.NODE_ENV === 'production' && process.env.SCALINGO_REDIS_URL
Expand Down
934 changes: 784 additions & 150 deletions api/source/test-e2e/__snapshots__/index.test.ts.snap

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/source/test-e2e/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('e2e test mon-entreprise api', () => {
{
valeur:
'dirigeant . auto-entrepreneur . cotisations et contributions',
unité: '€/an',
unité: '€ / an',
},
'dirigeant . rémunération . impôt',
'dirigeant . auto-entrepreneur . revenu net . après impôt',
Expand Down
37 changes: 19 additions & 18 deletions api/source/v1unitéAdapterMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { BaseContext } from 'koa'

export default async function v1unitéAdapterMiddleware(
ctx: BaseContext,
next: () => Promise<unknown>
) {
if (!ctx.path.startsWith('/api/v1/evaluate')) {
return await next()
}
import Router from '@koa/router'

if (!ctx.body) {
return await next()
}
const body = ctx.body as Record<string, unknown>
ctx.body = deepMap(body, (value, key) => {
if (key === 'unité' && typeof value === 'string') {
return value.replace(' /', '/').replace(' /', '/')
export default function v1unitéAdapterMiddleware() {
const router = new Router()

router.post('/evaluate', async (ctx, next) => {
if (!ctx.request.body) {
return next()
}

return value
ctx.request.body = deepMap(ctx.request.body, (value, key) => {
if (key === 'unité' && typeof value === 'string') {
const newValue = value.replace(' /', '/').replace('/ ', '/')

return newValue
}

return value
})

return next()
})

await next()
return router.routes()
}

function deepMap(
Expand Down
4 changes: 4 additions & 0 deletions exoneration-covid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.0-rc.1

Use publicodes v1.0.0-rc.4

## 0.6.0

Exporte les règles au format json pour optimiser le chargement
Expand Down
7 changes: 3 additions & 4 deletions exoneration-covid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "exoneration-covid",
"version": "0.5.0",
"version": "1.0.0-rc.1",
"description": "Les règles publicodes pour le calcul de l'exonération de cotisations covid (année 2021)",
"main": "./dist/index.js",
"types": "./index.d.ts",
Expand All @@ -18,11 +18,10 @@
"type": "module",
"devDependencies": {
"js-yaml": "^4.1.0",
"onchange": "^7.1.0",
"publicodes": "^1.0.0-rfc.1"
"onchange": "^7.1.0"
},
"peerDependencies": {
"publicodes": "^1.0.0-beta.55"
"publicodes": "^1.0.0-rc.4"
},
"scripts": {
"build": "node ../scripts/build-rules.js",
Expand Down
Loading

0 comments on commit 94d56d1

Please sign in to comment.