v28
This commit is contained in:
@@ -99,21 +99,40 @@ export class LeaguesService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get team's matches (past + upcoming)
|
||||
* Get team's matches (past + upcoming) with pagination
|
||||
*/
|
||||
async getTeamRecentMatches(teamId: string, limit: number = 50) {
|
||||
return this.prisma.match.findMany({
|
||||
where: {
|
||||
OR: [{ homeTeamId: teamId }, { awayTeamId: teamId }],
|
||||
},
|
||||
include: {
|
||||
homeTeam: true,
|
||||
awayTeam: true,
|
||||
league: { include: { country: true } },
|
||||
},
|
||||
orderBy: { mstUtc: "desc" },
|
||||
take: limit,
|
||||
});
|
||||
async getTeamRecentMatches(
|
||||
teamId: string,
|
||||
page: number = 1,
|
||||
limit: number = 20,
|
||||
) {
|
||||
const skip = (page - 1) * limit;
|
||||
const where = {
|
||||
OR: [{ homeTeamId: teamId }, { awayTeamId: teamId }],
|
||||
};
|
||||
|
||||
const [data, total] = await this.prisma.$transaction([
|
||||
this.prisma.match.findMany({
|
||||
where,
|
||||
include: {
|
||||
homeTeam: true,
|
||||
awayTeam: true,
|
||||
league: { include: { country: true } },
|
||||
},
|
||||
orderBy: { mstUtc: "desc" },
|
||||
skip,
|
||||
take: limit,
|
||||
}),
|
||||
this.prisma.match.count({ where }),
|
||||
]);
|
||||
|
||||
return {
|
||||
data,
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user