Add /api/statistics/type GET proxy call
This commit is contained in:
parent
7fabc142bc
commit
9e1b0a0287
27
src/routes/api/statistics/type/+server.ts
Normal file
27
src/routes/api/statistics/type/+server.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import type { ErrorMessage } from "$lib/api";
|
||||
import { get_stats_for, type StatsTypeCurrencyChart } from "$lib/entities";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
function isErrorMessage(value: any): value is ErrorMessage {
|
||||
return value && typeof value.message === 'string';
|
||||
}
|
||||
|
||||
export const GET: RequestHandler = async ({ cookies }): Promise<Response> => {
|
||||
const session = cookies.get('session');
|
||||
|
||||
// const queryParams = url.searchParams.toString();
|
||||
// Check if the entity is valid
|
||||
if (!session) {
|
||||
return new Response(JSON.stringify("no cookies"), { status: 401 });
|
||||
}
|
||||
|
||||
// TypeScript type inference for entity
|
||||
const result = await get_stats_for<StatsTypeCurrencyChart[]>("type", session);
|
||||
|
||||
if (isErrorMessage(result)) {
|
||||
console.log("ERROR");
|
||||
return new Response(JSON.stringify(result), { status: 500 });
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(result), { status: 200 });
|
||||
}
|
Loading…
Reference in New Issue
Block a user