-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use searchParams everywhere and use GET endpoints instead of client s…
…ide sorting
- Loading branch information
Showing
11 changed files
with
129 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import dbConnect from '../../../lib/dbConnect'; | ||
import FlatgroundTrick from '../../../models/FlatgroundTrick'; | ||
import { getFullGrindName, getFullManualName, getFullTrickName } from '../../../lib/commonUtils'; | ||
import { requireAuth } from '../../../lib/serverUtils'; | ||
import Grind from '../../../models/Grind'; | ||
import Manual from '../../../models/Manual'; | ||
|
||
export default async function handler(req, res) { | ||
const { method, query } = req; | ||
|
||
await dbConnect(); | ||
const { authQuery } = await requireAuth(req, res); | ||
|
||
switch (method) { | ||
case 'GET': | ||
try { | ||
const where = { ...authQuery }; | ||
|
||
if (query.countOnly === 'true') { | ||
const count = await FlatgroundTrick.countDocuments({ ...authQuery, ...extraQuery }); | ||
return res.status(200).json({ success: true, data: count }); | ||
} | ||
|
||
const flatgroundTricks = await FlatgroundTrick.find({ ...authQuery, ...extraQuery }).lean(); | ||
const flatgroundTricksData = flatgroundTricks.map((flatgroundTrick) => ({ | ||
...flatgroundTrick, | ||
trick: getFullTrickName(flatgroundTrick), | ||
})); | ||
|
||
const grinds = await Grind.find({ ...authQuery, ...extraQuery }).lean(); | ||
const grindsData = grinds.map((grind) => ({ ...grind, trick: getFullGrindName(grind) })); | ||
|
||
const manuals = await Manual.find({ ...authQuery, ...extraQuery }).lean(); | ||
const manualsData = manuals.map((manual) => ({ ...manual, trick: getFullManualName(manual) })); | ||
|
||
res.status(200).json({ success: true, data }); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(400).json({ success: false, error: error.message }); | ||
} | ||
break; | ||
default: | ||
res.status(400).json({ success: false, error: `Unhandled request method: ${method}` }); | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.