Skip to content
Permalink
05a0d192c3
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
49 lines (44 sloc) 1.32 KB
function errorResponse(error: string, status = 400): Response {
return new Response(JSON.stringify({ error }), {
headers: {
"content-type": "application/json",
},
status,
});
}
export default function (
selectedDepartments: string[],
end: any,
reason: any,
start: any,
userDepartments?: string[],
): void | Response {
if (!userDepartments)
return errorResponse("Not part of any departments", 403);
if (
!Array.isArray(selectedDepartments) ||
!selectedDepartments.length ||
typeof end !== "string" ||
typeof reason !== "string" ||
typeof start !== "string"
)
return errorResponse("Invalid notice");
if (!selectedDepartments.every((dept) => userDepartments.includes(dept)))
return errorResponse(
"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 (
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 errorResponse("Dates are invalid");
}