app
components
data
functions
api
admin-apps
appeals
auth
data-transfers
events-team
events
[id]
[id].ts
_middleware.ts
list.ts
new.ts
points
strikes
team-members
game-appeals
game-bans
gme
inactivity
infractions
me
mod-queue
reports
short-links
uploads
[[path]].ts
coconut.ts
events.ts
webview-captcha.ts
_middleware.ts
common.ts
email.ts
gcloud.ts
permissions.ts
roblox-open-cloud.ts
upload.ts
public
.gitignore
.node-version
.prettierignore
OFL.txt
README.md
emotion-server.js
index.css
index.d.ts
package-lock.json
package.json
remix.config.js
server.ts
theme.ts
tsconfig.json
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import { jsonError, jsonResponse } from "../../../common.js";
|
|
|
|
export async function onRequestGet(context: RequestContext) {
|
|
const url = new URL(context.request.url);
|
|
const month = parseInt(url.searchParams.get("month") ?? "");
|
|
const year = parseInt(url.searchParams.get("year") ?? "");
|
|
|
|
if (isNaN(month) || isNaN(year))
|
|
return jsonError("Invalid month or year", 400);
|
|
|
|
const currentYear = new Date().getUTCFullYear();
|
|
const currentMonth = new Date().getUTCMonth() + 1;
|
|
|
|
if (currentYear < year || (currentYear === year && currentMonth < month))
|
|
return jsonError("Cannot get events for a time in the future", 400);
|
|
|
|
const eventRecords = await context.env.D1.prepare(
|
|
"SELECT answer, approved, created_by, day, details, month, pending, performed_at, type, year FROM events WHERE month = ? AND year = ? ORDER BY day ASC;",
|
|
)
|
|
.bind(month, year)
|
|
.all();
|
|
|
|
if (!eventRecords.success) return jsonError("Failed to retrieve events", 400);
|
|
|
|
return jsonResponse(JSON.stringify(eventRecords.results));
|
|
}
|