Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from waldeck-dev/feat/list-matches
Browse files Browse the repository at this point in the history
Feat/list matches
  • Loading branch information
waldeck-dev authored Sep 25, 2022
2 parents 69f3973 + af4fb76 commit b78a999
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 1 deletion.
7 changes: 7 additions & 0 deletions back/src/api/match/controllers/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
5 changes: 5 additions & 0 deletions back/src/api/match/routes/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

module.exports = {
routes: [
{
method: 'GET',
path: '/matches',
handler: 'match.find'
},
{
method: 'PUT',
path: '/matches',
Expand Down
162 changes: 162 additions & 0 deletions worker/db/countries.json
Original file line number Diff line number Diff line change
@@ -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": "🇬🇭"
}
}
9 changes: 8 additions & 1 deletion worker/db/matches.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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<string, ICountry>)[name];
Object.assign(m[team], country);
});
await db.matches.create(m.id!.toString(), m);
}

Expand Down
11 changes: 11 additions & 0 deletions worker/types/fd-org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,3 +54,9 @@ export interface IMatch {
awayTeam: ITeam;
score: IScore;
}

export interface ICountry {
nameFr: string;
iso2: string;
emoji: string;
}

0 comments on commit b78a999

Please sign in to comment.