Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
car-crushers-portal/functions/api/inactivity/validate.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
48 lines (41 sloc)
1.43 KB
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
import { jsonError } from "../../common.js"; | |
export default function ( | |
selectedDepartments: string[], | |
end: any, | |
hiatus: any, | |
reason: any, | |
start: any, | |
userDepartments?: string[], | |
): void | Response { | |
if (!userDepartments) return jsonError("Not part of any departments", 403); | |
if ( | |
!Array.isArray(selectedDepartments) || | |
!selectedDepartments.length || | |
typeof end !== "string" || | |
typeof reason !== "string" || | |
typeof start !== "string" | |
) | |
return jsonError("Invalid notice", 400); | |
if (!selectedDepartments.every((dept) => userDepartments.includes(dept))) | |
return jsonError( | |
"Cannot file an inactivity notice in a department you are not part of", | |
403, | |
); | |
const endDate = new Date(end); | |
const now = new Date(); | |
const startDate = new Date(start); | |
if (typeof hiatus !== "undefined" && typeof hiatus !== "boolean") | |
return jsonError("Invalid notice", 400); | |
if (!["DM", "WM"].find((d) => selectedDepartments.includes(d)) && hiatus) | |
return jsonError("Only discord and wall mods can file hiatuses", 400); | |
if ( | |
isNaN(endDate.getFullYear()) || | |
isNaN(startDate.getFullYear()) || | |
endDate.getFullYear() < now.getFullYear() || | |
endDate.getFullYear() > now.getFullYear() + 1 || | |
startDate.getFullYear() < now.getFullYear() || | |
startDate.getFullYear() > now.getFullYear() + 1 || | |
endDate.valueOf() < startDate.valueOf() | |
) | |
return jsonError("Dates are invalid", 400); | |
} |