Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create start of new event endpoint
  • Loading branch information
regalijan committed Jan 9, 2024
1 parent ecc1791 commit 4072ad2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions functions/api/events-team/events/new.ts
@@ -0,0 +1,23 @@
import { jsonError } from "../../../common.js";

export async function onRequestPost(context: RequestContext) {
const { day, details, type } = context.data.body;
const now = new Date();
const currentMonth = now.getUTCMonth();
const currentYear = now.getUTCFullYear();

if (
typeof day !== "number" ||
day < 1 ||
// Last day of that month
day > new Date(currentYear, currentMonth, 0).getUTCDate() ||
// Stop people sending weird decimal days
parseInt(day.toString()) !== day ||
typeof details !== "string" ||
!details.length ||
!["fotd", "gamenight", "rotw", "qotd"].includes(type)
)
return jsonError("Invalid body", 400);


}

0 comments on commit 4072ad2

Please sign in to comment.