Skip to content

Commit

Permalink
updat countries
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Jul 22, 2024
1 parent 913328d commit 1c3c33c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/robotoff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from "axios";
import { ROBOTOFF_API_URL, IS_DEVELOPMENT_MODE, OFF_IMAGE_URL } from "./const";
import { getLang } from "./localeStorageManager";
import COUNTRIES from "./assets/countries.json";
import { reformatValueTag, removeEmptyKeys } from "./utils";

export interface QuestionInterface {
Expand All @@ -16,6 +17,13 @@ export interface QuestionInterface {

type GetQuestionsResponse = { count: number; questions: QuestionInterface[] };

function countryId2countryCode(id: string | null) {
if (id === null) {
return null;
}
return COUNTRIES.find((c) => c.id === id)?.countryCode;
}

const robotoff = {
annotate(insightId: string, annotation) {
if (IS_DEVELOPMENT_MODE) {
Expand Down Expand Up @@ -64,7 +72,9 @@ const robotoff = {
insight_types: insightType,
value_tag: valueTag,
brands: reformatValueTag(brandFilter),
country: countryFilter !== "en:world" ? countryFilter : null,
countries: countryId2countryCode(
countryFilter !== "en:world" ? countryFilter : null,
),
campaign,
predictor,
order_by: sortByPopularity ? "popularity" : "random",
Expand Down Expand Up @@ -227,6 +237,7 @@ const robotoff = {
return axios.get(
`${ROBOTOFF_API_URL}/questions/unanswered/?${Object.keys({
...params,
countries: countryId2countryCode(params.country),
page,
})
.filter((key) => params[key] !== undefined)
Expand Down

0 comments on commit 1c3c33c

Please sign in to comment.