Skip to content

Commit

Permalink
Merge pull request #13 from blarth/fix/my-duels
Browse files Browse the repository at this point in the history
fix: all duels
  • Loading branch information
blarth committed Aug 4, 2022
2 parents a266617 + 5f79a80 commit 397bd67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/repositories/duelUserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ export async function findAll(){
},
}
},
id : true
id : true,
match : {
select : {
finishedAt : true
}
}
}
})
}
6 changes: 3 additions & 3 deletions src/services/duelUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as duelUserRepository from "../repositories/duelUserRepository.js"
export async function findAllGivenId(id : number){
const duels = await duelUserRepository.findAllGivenId(id)
const duelsUpcoming = duels.filter(el => el.duel.match.result === 0)
const duelsLost = duels.filter(el => el.duel.match.result === el.team.id)
const duelsWon = duels.filter(el => el.duel.match.result !== el.team.id && el.duel.match.result !== 0)
const duelsLost = duels.filter(el => el.duel.match.result !== el.team.id && el.duel.match.result !== 0)
const duelsWon = duels.filter(el => el.duel.match.result === el.team.id && el.duel.match.result !== 0)

const duelsMapped = {
duelsUpcoming,
Expand All @@ -17,6 +17,6 @@ export async function findAllGivenId(id : number){

export async function findAll(){
const duels = await duelUserRepository.findAll()
const duelsFiltered = duels.filter(el => el.duelUser.length < 2)
const duelsFiltered = duels.filter(el => el.duelUser.length < 2 && el.match.finishedAt === null)
return duelsFiltered
}
2 changes: 2 additions & 0 deletions src/services/getDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ async function getDataResult() {
openDuels.forEach(async (duel) => {
const amount = duel.duelUser.reduce((total, acc) => total + acc.bet, 0)
const winner = duel.duelUser.find((duelist) => duelist.teamId === id)
console.log(winner)
console.log(amount)
await duelsRepository.update(winner.userId, amount)
})
}
Expand Down

0 comments on commit 397bd67

Please sign in to comment.