Skip to content
Permalink
7ec760efd4
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
1 contributor

Users who have contributed to this file

48 lines (41 sloc) 1.11 KB
import validateInactivity from "./validate.js";
export async function onRequestPost(context: RequestContext) {
const { departments, end, reason, start } = context.data.body;
const validationFailureResponse = validateInactivity(
departments,
end,
reason,
start,
context.data.departments,
);
if (validationFailureResponse) return validationFailureResponse;
const inactivityId =
context.data.current_user.id +
(context.request.headers.get("cf-ray") as string).split("-")[0] +
Date.now().toString();
await context.env.DATA.put(
`inactivity_${inactivityId}`,
JSON.stringify({
created_at: Date.now(),
departments,
end,
reason,
start,
user: {
id: context.data.current_user.id,
username: context.data.current_user.username,
},
}),
{
expirationTtl: 63072000,
},
);
await context.env.D1.prepare(
"INSERT INTO inactivity_notices (created_at, id, user) VALUES (?, ?, ?);",
)
.bind(Date.now(), inactivityId, context.data.current_user.id)
.run();
return new Response(null, {
status: 204,
});
}