|
@@ -11,7 +11,8 @@ export const GET = withAuth(async (request) => {
|
|
|
const { searchParams } = new URL(request.url);
|
|
|
const current = parseInt(searchParams.get("current") || "1");
|
|
|
const pageSize = parseInt(searchParams.get("pageSize") || "10");
|
|
|
- const matchInfo = searchParams.get("matchInfo");
|
|
|
+ const homeTeam = searchParams.get("homeTeam");
|
|
|
+ const awayTeam = searchParams.get("awayTeam");
|
|
|
const username = searchParams.get("username");
|
|
|
const type = searchParams.get("type"); // 新增type参数来筛选运动类型
|
|
|
|
|
@@ -29,7 +30,7 @@ export const GET = withAuth(async (request) => {
|
|
|
// 处理其他搜索参数
|
|
|
for (const [key, value] of searchParams.entries()) {
|
|
|
if (
|
|
|
- ["current", "pageSize", "matchInfo", "username", "type"].includes(key)
|
|
|
+ ["current", "pageSize", "homeTeam", "awayTeam", "username", "type"].includes(key)
|
|
|
)
|
|
|
continue;
|
|
|
|
|
@@ -112,27 +113,22 @@ export const GET = withAuth(async (request) => {
|
|
|
{ $sort: { createdAt: -1 } },
|
|
|
];
|
|
|
|
|
|
- if (matchInfo) {
|
|
|
+ if (homeTeam) {
|
|
|
pipeline.push({
|
|
|
$match: {
|
|
|
- $or: [
|
|
|
- {
|
|
|
- "matchDetails.homeTeam.name": {
|
|
|
- $regex: matchInfo,
|
|
|
- $options: "i",
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- "matchDetails.awayTeam.name": {
|
|
|
- $regex: matchInfo,
|
|
|
- $options: "i",
|
|
|
- },
|
|
|
- },
|
|
|
- ],
|
|
|
+ "matchDetails.homeTeam.name": homeTeam,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (awayTeam) {
|
|
|
+ pipeline.push({
|
|
|
+ $match: {
|
|
|
+ "matchDetails.awayTeam.name": awayTeam,
|
|
|
},
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
const countPipeline = [...pipeline, { $count: "total" }];
|
|
|
const totalResult = await Prediction.aggregate(countPipeline);
|
|
|
const totalCount = totalResult.length > 0 ? totalResult[0].total : 0;
|
|
@@ -152,7 +148,8 @@ export const GET = withAuth(async (request) => {
|
|
|
...prediction,
|
|
|
match: undefined,
|
|
|
matchDetails: undefined,
|
|
|
- matchInfo: `${prediction.matchDetails.homeTeam.name}:${prediction.matchDetails.awayTeam.name}`,
|
|
|
+ homeTeam: prediction.matchDetails.homeTeam.name,
|
|
|
+ awayTeam: prediction.matchDetails.awayTeam.name
|
|
|
};
|
|
|
|
|
|
// 根据运动类型添加特定信息
|
|
@@ -194,8 +191,6 @@ export const POST = withAuth(async (request) => {
|
|
|
const body = await request.json();
|
|
|
const { userId, predictions } = body;
|
|
|
|
|
|
- console.log(111, userId, predictions);
|
|
|
-
|
|
|
if (!userId) {
|
|
|
return NextResponse.json(
|
|
|
{ success: false, error: "请先登录" },
|
|
@@ -224,9 +219,6 @@ export const POST = withAuth(async (request) => {
|
|
|
match: matchId,
|
|
|
});
|
|
|
|
|
|
- console.log(111, pred, matchId);
|
|
|
- console.log("existingPrediction", existingPrediction);
|
|
|
-
|
|
|
if (existingPrediction) {
|
|
|
// 更新预测
|
|
|
if (type === "football" && football) {
|
|
@@ -247,7 +239,6 @@ export const POST = withAuth(async (request) => {
|
|
|
football.totalGoals.prediction;
|
|
|
}
|
|
|
} else if (type === "basketball" && basketball) {
|
|
|
- console.log(222);
|
|
|
|
|
|
if (basketball.whoWillWin) {
|
|
|
existingPrediction.basketball.whoWillWin.prediction =
|
|
@@ -273,24 +264,24 @@ export const POST = withAuth(async (request) => {
|
|
|
type,
|
|
|
...(type === "football" &&
|
|
|
football && {
|
|
|
- football: {
|
|
|
- whoWillWin: { prediction: football.whoWillWin.prediction },
|
|
|
- firstTeamToScore: {
|
|
|
- prediction: football.firstTeamToScore.prediction,
|
|
|
- firstTeamToScoreLogo:
|
|
|
- football.firstTeamToScore.firstTeamToScoreLogo,
|
|
|
- },
|
|
|
- totalGoals: { prediction: football.totalGoals.prediction },
|
|
|
+ football: {
|
|
|
+ whoWillWin: { prediction: football.whoWillWin.prediction },
|
|
|
+ firstTeamToScore: {
|
|
|
+ prediction: football.firstTeamToScore.prediction,
|
|
|
+ firstTeamToScoreLogo:
|
|
|
+ football.firstTeamToScore.firstTeamToScoreLogo,
|
|
|
},
|
|
|
- }),
|
|
|
+ totalGoals: { prediction: football.totalGoals.prediction },
|
|
|
+ },
|
|
|
+ }),
|
|
|
...(type === "basketball" &&
|
|
|
basketball && {
|
|
|
- basketball: {
|
|
|
- whoWillWin: { prediction: basketball.whoWillWin.prediction },
|
|
|
- spread: { prediction: basketball.spread.prediction },
|
|
|
- totalPoints: { prediction: basketball.totalPoints.prediction },
|
|
|
- },
|
|
|
- }),
|
|
|
+ basketball: {
|
|
|
+ whoWillWin: { prediction: basketball.whoWillWin.prediction },
|
|
|
+ spread: { prediction: basketball.spread.prediction },
|
|
|
+ totalPoints: { prediction: basketball.totalPoints.prediction },
|
|
|
+ },
|
|
|
+ }),
|
|
|
});
|
|
|
|
|
|
const savedPrediction = await newPrediction.save();
|
|
@@ -323,24 +314,24 @@ export const PUT = withAuth(async (request) => {
|
|
|
type,
|
|
|
...(type === "football" &&
|
|
|
football && {
|
|
|
- football: {
|
|
|
- whoWillWin: { prediction: football.whoWillWin.prediction },
|
|
|
- firstTeamToScore: {
|
|
|
- prediction: football.firstTeamToScore.prediction,
|
|
|
- firstTeamToScoreLogo:
|
|
|
- football.firstTeamToScore.firstTeamToScoreLogo,
|
|
|
- },
|
|
|
- totalGoals: { prediction: football.totalGoals.prediction },
|
|
|
+ football: {
|
|
|
+ whoWillWin: { prediction: football.whoWillWin.prediction },
|
|
|
+ firstTeamToScore: {
|
|
|
+ prediction: football.firstTeamToScore.prediction,
|
|
|
+ firstTeamToScoreLogo:
|
|
|
+ football.firstTeamToScore.firstTeamToScoreLogo,
|
|
|
},
|
|
|
- }),
|
|
|
+ totalGoals: { prediction: football.totalGoals.prediction },
|
|
|
+ },
|
|
|
+ }),
|
|
|
...(type === "basketball" &&
|
|
|
basketball && {
|
|
|
- basketball: {
|
|
|
- whoWillWin: { prediction: basketball.whoWillWin.prediction },
|
|
|
- spread: { prediction: basketball.spread.prediction },
|
|
|
- totalPoints: { prediction: basketball.totalPoints.prediction },
|
|
|
- },
|
|
|
- }),
|
|
|
+ basketball: {
|
|
|
+ whoWillWin: { prediction: basketball.whoWillWin.prediction },
|
|
|
+ spread: { prediction: basketball.spread.prediction },
|
|
|
+ totalPoints: { prediction: basketball.totalPoints.prediction },
|
|
|
+ },
|
|
|
+ }),
|
|
|
};
|
|
|
|
|
|
const updatedPrediction = await Prediction.findByIdAndUpdate(
|