Skip to content

Commit

Permalink
Merge pull request #989 from betagouv/main
Browse files Browse the repository at this point in the history
MEP [TRELLO-2598] Filter categories for mobile
  • Loading branch information
charlescd authored Dec 19, 2024
2 parents c0fde68 + b50975f commit aab8001
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion mobile-tools/src/controllers/categories.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const CategoriesController = Router()
CategoriesController.get('/', async (req: Request<{}, {}, {}, QueryParams>, res, next) => {
try {
const lang = req.query.lang ?? 'fr'
return res.status(200).send(categories[lang].sort((a, b) => Number(a.id) - Number(b.id)))
return res.status(200).send(categories[lang])
} catch (err) {
next(err)
}
Expand Down
48 changes: 28 additions & 20 deletions mobile-tools/src/services/categories.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,35 @@ const anomaliesEn = JSON.parse(fs.readFileSync('../shared/anomalies/json/anomali
export const minimizedAnomaliesFr = JSON.parse(fs.readFileSync('../shared/anomalies/json/minimized-anomalies_fr.json', 'utf-8'))
export const minimizedAnomaliesEn = JSON.parse(fs.readFileSync('../shared/anomalies/json/minimized-anomalies_en.json', 'utf-8'))

const categoriesFr: Category[] = anomaliesFr.map((anomaly: any) => {
return {
category: anomaly.title,
description: anomaly.description,
id: anomaly.id,
path: anomaly.path,
img: `${Config.websiteUrl}/image/pictos/${anomaly.img}.png`,
}
})
const specialCategories = ['OpenFoodFacts', 'RappelConso']

const categoriesEn: Category[] = anomaliesEn.map((anomaly: any) => {
return {
category: anomaly.title,
description: anomaly.description,
id: anomaly.id,
path: anomaly.path,
img: `${Config.websiteUrl}/image/pictos/${anomaly.img}.png`,
}
})
const categoriesFr: Category[] = anomaliesFr
.filter((anomaly: any) => !anomaly.hidden && !anomaly.isHiddenDemoCategory)
.filter((anomaly: any) => !anomaly.specialCategory)
.map((anomaly: any) => {
return {
category: anomaly.title,
description: anomaly.description,
id: anomaly.id,
path: anomaly.path,
img: `${Config.websiteUrl}/image/pictos/${anomaly.img}.png`,
}
})

const categoriesEn: Category[] = anomaliesEn
.filter((anomaly: any) => !anomaly.hidden && !anomaly.isHiddenDemoCategory)
.filter((anomaly: any) => !anomaly.specialCategory)
.map((anomaly: any) => {
return {
category: anomaly.title,
description: anomaly.description,
id: anomaly.id,
path: anomaly.path,
img: `${Config.websiteUrl}/image/pictos/${anomaly.img}.png`,
}
})

export const categories = {
fr: categoriesFr,
en: categoriesEn,
fr: categoriesFr.sort((a, b) => parseInt(a.id, 10) - parseInt(b.id, 10)),
en: categoriesEn.sort((a, b) => parseInt(a.id, 10) - parseInt(b.id, 10)),
}

0 comments on commit aab8001

Please sign in to comment.