|
@@ -129,10 +129,53 @@ export async function GET(request) {
|
|
|
|
|
|
const skip = (current - 1) * pageSize;
|
|
|
const totalMatches = await Match.countDocuments(searchQuery);
|
|
|
- const matchesData = await Match.find(searchQuery)
|
|
|
- .sort({ date: -1, time: 1 })
|
|
|
- .skip(skip)
|
|
|
- .limit(pageSize);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const matchesData = await Match.aggregate([
|
|
|
+
|
|
|
+ {
|
|
|
+ $match: searchQuery
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ $lookup: {
|
|
|
+ from: "predictions",
|
|
|
+ localField: "_id",
|
|
|
+ foreignField: "match",
|
|
|
+ as: "predictions"
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ $addFields: {
|
|
|
+ canyuNumber: { $size: "$predictions" }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ $project: {
|
|
|
+ predictions: 0,
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ $sort: {
|
|
|
+ date: -1,
|
|
|
+ time: 1
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ $skip: skip
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ $limit: pageSize
|
|
|
+ }
|
|
|
+ ]);
|
|
|
|
|
|
response = NextResponse.json({
|
|
|
success: true,
|