From 010133b2057d211140756602d212e6ac1797c678 Mon Sep 17 00:00:00 2001 From: Valentin Date: Sun, 25 Sep 2022 20:38:03 +0200 Subject: [PATCH 1/2] Add extra country data on the fly --- worker/db/countries.json | 162 +++++++++++++++++++++++++++++++++++++++ worker/db/matches.ts | 9 ++- worker/types/fd-org.ts | 11 +++ 3 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 worker/db/countries.json diff --git a/worker/db/countries.json b/worker/db/countries.json new file mode 100644 index 0000000..4dbd258 --- /dev/null +++ b/worker/db/countries.json @@ -0,0 +1,162 @@ +{ + "Senegal": { + "nameFr": "Sรฉnรฉgal", + "iso2": "SE", + "emoji": "๐Ÿ‡ธ๐Ÿ‡ณ" + }, + "Netherlands": { + "nameFr": "Pays-Bas", + "iso2": "NL", + "emoji": "๐Ÿ‡ณ๐Ÿ‡ฑ" + }, + "Qatar": { + "nameFr": "Qatar", + "iso2": "QA", + "emoji": "๐Ÿ‡ถ๐Ÿ‡ฆ" + }, + "Ecuador": { + "nameFr": "Equateur", + "iso2": "EC", + "emoji": "๐Ÿ‡ช๐Ÿ‡จ" + }, + "England": { + "nameFr": "Angleterre", + "iso2": "GB-ENG", + "emoji": "๐Ÿด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ" + }, + "Iran": { + "nameFr": "Iran", + "iso2": "IR", + "emoji": "๐Ÿ‡ฎ๐Ÿ‡ท" + }, + "United States": { + "nameFr": "Etats-Unis", + "iso2": "US", + "emoji": "๐Ÿ‡บ๐Ÿ‡ธ" + }, + "Wales": { + "nameFr": "Pays de Galles", + "iso2": "GB-WLS", + "emoji": "๐Ÿด๓ ง๓ ข๓ ท๓ ฌ๓ ณ๓ ฟ" + }, + "Argentina": { + "nameFr": "Argentine", + "iso2": "AR", + "emoji": "๐Ÿ‡ฆ๐Ÿ‡ท" + }, + "Saudi Arabia": { + "nameFr": "Arabie Saoudite", + "iso2": "SA", + "emoji": "๐Ÿ‡ธ๐Ÿ‡ฆ" + }, + "Mexico": { + "nameFr": "Mexique", + "iso2": "MX", + "emoji": "๐Ÿ‡ฒ๐Ÿ‡ฝ" + }, + "Poland": { + "nameFr": "Pologne", + "iso2": "PL", + "emoji": "๐Ÿ‡ต๐Ÿ‡ฑ" + }, + "Denmark": { + "nameFr": "Danemark", + "iso2": "DK", + "emoji": "๐Ÿ‡ฉ๐Ÿ‡ฐ" + }, + "Tunisia": { + "nameFr": "Tunisie", + "iso2": "TN", + "emoji": "๐Ÿ‡น๐Ÿ‡ณ" + }, + "France": { + "nameFr": "France", + "iso2": "FR", + "emoji": "๐Ÿ‡ซ๐Ÿ‡ท" + }, + "Australia": { + "nameFr": "Australie", + "iso2": "AU", + "emoji": "๐Ÿ‡ฆ๐Ÿ‡บ" + }, + "Germany": { + "nameFr": "Allemagne", + "iso2": "GE", + "emoji": "๐Ÿ‡ฌ๐Ÿ‡ช" + }, + "Japan": { + "nameFr": "Japon", + "iso2": "JP", + "emoji": "๐Ÿ‡ฏ๐Ÿ‡ต" + }, + "Spain": { + "nameFr": "Espagne", + "iso2": "ES", + "emoji": "๐Ÿ‡ช๐Ÿ‡ธ" + }, + "Costa Rica": { + "nameFr": "Costa Rica", + "iso2": "CR", + "emoji": "๐Ÿ‡จ๐Ÿ‡ท" + }, + "Morocco": { + "nameFr": "Maroc", + "iso2": "MA", + "emoji": "๐Ÿ‡ฒ๐Ÿ‡ฆ" + }, + "Croatia": { + "nameFr": "Croatie", + "iso2": "HR", + "emoji": "๐Ÿ‡ญ๐Ÿ‡ท" + }, + "Belgium": { + "nameFr": "Belgique", + "iso2": "BE", + "emoji": "๐Ÿ‡ง๐Ÿ‡ช" + }, + "Canada": { + "nameFr": "Canada", + "iso2": "CA", + "emoji": "๐Ÿ‡จ๐Ÿ‡ฆ" + }, + "Switzerland": { + "nameFr": "Suisse", + "iso2": "CH", + "emoji": "๐Ÿ‡จ๐Ÿ‡ญ" + }, + "Cameroon": { + "nameFr": "Cameroun", + "iso2": "CM", + "emoji": "๐Ÿ‡จ๐Ÿ‡ฒ" + }, + "Brazil": { + "nameFr": "Brรฉsil", + "iso2": "BR", + "emoji": "๐Ÿ‡ง๐Ÿ‡ท" + }, + "Serbia": { + "nameFr": "Serbie", + "iso2": "RS", + "emoji": "๐Ÿ‡ท๐Ÿ‡ธ" + }, + "Uruguay": { + "nameFr": "Uruguay", + "iso2": "UY", + "emoji": "๐Ÿ‡บ๐Ÿ‡พ" + }, + "South Korea": { + "nameFr": "Corรฉe du Sud", + "iso2": "KR", + "emoji": "๐Ÿ‡ฐ๐Ÿ‡ท" + }, + "Portugal": { + "nameFr": "Portugal", + "iso2": "PT", + "emoji": "๐Ÿ‡ต๐Ÿ‡น" + }, + "Ghana": { + "nameFr": "Ghana", + "iso2": "GH", + "emoji": "๐Ÿ‡ฌ๐Ÿ‡ญ" + } +} \ No newline at end of file diff --git a/worker/db/matches.ts b/worker/db/matches.ts index fc99588..3cc9fa4 100644 --- a/worker/db/matches.ts +++ b/worker/db/matches.ts @@ -1,7 +1,8 @@ import { db } from "./db.ts"; import { getAuthHeaders as getFdOrgHeaders } from "../db/fd-org.ts"; import { getAuthHeaders as getBackHeaders } from "../db/back.ts"; -import { IMatch } from "../types/fd-org.ts"; +import { ICountry, IMatch, Team } from "../types/fd-org.ts"; +import Countries from "./countries.json" assert { type: "json" }; async function fetchMatches(competitionId: number) { const response = await fetch( @@ -15,6 +16,12 @@ async function fetchMatches(competitionId: number) { } export async function createMatch(m: IMatch) { + [Team.AWAY, Team.HOME].forEach((team: Team) => { + const name = m[team].name; + if (!name) return; + const country = (Countries as Record)[name]; + Object.assign(m[team], country); + }); await db.matches.create(m.id!.toString(), m); } diff --git a/worker/types/fd-org.ts b/worker/types/fd-org.ts index e6b5b9f..a9f75de 100644 --- a/worker/types/fd-org.ts +++ b/worker/types/fd-org.ts @@ -18,6 +18,11 @@ export enum Stage { GROUP_STAGE = "GROUP_STAGE", } +export enum Team { + HOME = "homeTeam", + AWAY = "awayTeam", +} + interface ITeam { id: number | null; name: string | null; @@ -49,3 +54,9 @@ export interface IMatch { awayTeam: ITeam; score: IScore; } + +export interface ICountry { + nameFr: string; + iso2: string; + emoji: string; +} From af4fb767c59790b916a9ba0c281132bc943229be Mon Sep 17 00:00:00 2001 From: Valentin Date: Sun, 25 Sep 2022 20:38:57 +0200 Subject: [PATCH 2/2] Add find route for matches --- back/src/api/match/controllers/match.js | 7 +++++++ back/src/api/match/routes/match.js | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/back/src/api/match/controllers/match.js b/back/src/api/match/controllers/match.js index 459d763..5f7b339 100644 --- a/back/src/api/match/controllers/match.js +++ b/back/src/api/match/controllers/match.js @@ -7,6 +7,13 @@ const { extractData } = require('../../../utils'); */ module.exports = { + find: async (ctx) => { + const matches = await strapi.entityService + .findMany('api::match.match'); + + return ctx.send({ data: matches }, 200); + }, + insert: async (ctx) => { const payload = ctx.request.body.data?.matches; if (!payload || !Array.isArray(payload)) { diff --git a/back/src/api/match/routes/match.js b/back/src/api/match/routes/match.js index ad3623b..ef6ded1 100644 --- a/back/src/api/match/routes/match.js +++ b/back/src/api/match/routes/match.js @@ -6,6 +6,11 @@ module.exports = { routes: [ + { + method: 'GET', + path: '/matches', + handler: 'match.find' + }, { method: 'PUT', path: '/matches',