-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
130 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { fetchChatEvents } from "@/queries/market"; | ||
import type { NextRequest } from "next/server"; | ||
import { stringifyJSON } from "utils"; | ||
|
||
type ChatSearchParams = { | ||
marketID: string | null; | ||
fromMarketNonce: string | null; | ||
}; | ||
|
||
export type ValidChatSearchParams = { | ||
marketID: string; | ||
fromMarketNonce: string; | ||
}; | ||
|
||
const isNumber = (s: string) => !isNaN(parseInt(s)); | ||
|
||
const isValidChatSearchParams = (params: ChatSearchParams): params is ValidChatSearchParams => { | ||
const { marketID, fromMarketNonce } = params; | ||
// prettier-ignore | ||
return ( | ||
marketID !== null && isNumber(marketID) && | ||
fromMarketNonce !== null && isNumber(fromMarketNonce) | ||
); | ||
}; | ||
|
||
export async function GET(request: NextRequest) { | ||
const searchParams = request.nextUrl.searchParams; | ||
const params: ChatSearchParams = { | ||
marketID: searchParams.get("marketID"), | ||
fromMarketNonce: searchParams.get("fromMarketNonce"), | ||
}; | ||
|
||
if (!isValidChatSearchParams(params)) { | ||
return new Response("Invalid chat search params.", { status: 400 }); | ||
} | ||
|
||
const marketID = Number(params.marketID); | ||
const fromMarketNonce = Number(params.fromMarketNonce); | ||
|
||
const res = await fetchChatEvents({ marketID, fromMarketNonce }); | ||
|
||
return new Response(stringifyJSON(res)); | ||
} |
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,43 @@ | ||
import { fetchSwapEvents } from "@/queries/market"; | ||
import type { NextRequest } from "next/server"; | ||
import { stringifyJSON } from "utils"; | ||
|
||
type SwapSearchParams = { | ||
marketID: string | null; | ||
fromMarketNonce: string | null; | ||
}; | ||
|
||
export type ValidSwapSearchParams = { | ||
marketID: string; | ||
fromMarketNonce: string; | ||
}; | ||
|
||
const isNumber = (s: string) => !isNaN(parseInt(s)); | ||
|
||
const isValidSwapSearchParams = (params: SwapSearchParams): params is ValidSwapSearchParams => { | ||
const { marketID, fromMarketNonce } = params; | ||
// prettier-ignore | ||
return ( | ||
marketID !== null && isNumber(marketID) && | ||
fromMarketNonce !== null && isNumber(fromMarketNonce) | ||
); | ||
}; | ||
|
||
export async function GET(request: NextRequest) { | ||
const searchParams = request.nextUrl.searchParams; | ||
const params: SwapSearchParams = { | ||
marketID: searchParams.get("marketID"), | ||
fromMarketNonce: searchParams.get("fromMarketNonce"), | ||
}; | ||
|
||
if (!isValidSwapSearchParams(params)) { | ||
return new Response("Invalid chat search params.", { status: 400 }); | ||
} | ||
|
||
const marketID = Number(params.marketID); | ||
const fromMarketNonce = Number(params.fromMarketNonce); | ||
|
||
const res = await fetchSwapEvents({ marketID, fromMarketNonce }); | ||
|
||
return new Response(stringifyJSON(res)); | ||
} |
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