OpenLigaDB / OpenLigaDB-Samples

Code-Samples und Issue-Tracker for using OpenLigaDB-Api
https://www.OpenLigaDB.de
Apache License 2.0
135 stars 17 forks source link

Neue property in Goal Objekt #73

Open xdream77 opened 3 months ago

xdream77 commented 3 months ago

Für meine Anzeige muss ich wissen, für welches Team dieses Tor gefallen ist. Unabhängig davon ob es ein Elfmeter, Eigentor oder was auch immer ist.

Zur Zeit setze ich die property goalFor selbst. Ich denke, dass das eine wichtige Information ist und es wäre cool, wenn wir das in die Source einbauen könnten.

Hier ist meine Implementierung in Javascript (bzw. beschränktem Typescript)

Ich modifiziere die Daten zwar ein bisschen, aber das Ergebnis ist erkennbar.

const modifyGoal = (goal: OldbGoal): WgdGoal => ({
    oldb_id: goal.goalID,
    home   : goal.scoreTeam1,
    away   : goal.scoreTeam2,
    minute : goal.matchMinute,
    scorer : {
        name   : goal.goalGetterName,
        oldb_id: goal.goalGetterID,
    },
    penalty : goal.isPenalty,
    ownGoal : goal.isOwnGoal,
    overtime: goal.isOvertime,
});

const addGoalFor = ({ goals }: OldbData) => goals.reduce( (acc, cur) => {
    const model = modifyGoal(cur);
    if (!acc.length) {
        model.goalFor = model.home > model.away ? 'home' : 'away';
    } else {
        model.goalFor = acc[acc.length - 1].home === model.home ? 'away' : 'home';
    }
    acc.push(model);
    return acc; 
}, [] as `WgdGoal[]);`