All files / apps/web/src/pages/api/utils cleanup.ts

16.66% Statements 1/6
100% Branches 0/0
0% Functions 0/1
16.66% Lines 1/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32          6x                                                    
import { createFileRoute } from "@tanstack/react-router";
 
import { router } from "~web/handlers/index";
import { getServerTrpcClient } from "~web/utils/server/trpc";
 
export const Route = createFileRoute("/api/utils/cleanup")({
	server: {
		handlers: {
			POST: async ({ request }) => {
				try {
					const client = getServerTrpcClient(router, request);
					const [
						{ count: removedSessions },
						{ count: removedResetPasswordIntentions },
					] = await Promise.all([
						client.sessions.cleanup.mutate(),
						client.resetPasswordIntentions.cleanup.mutate(),
					]);
 
					return new Response(
						`Removed ${removedSessions} sessions and ${removedResetPasswordIntentions} reset password intentions`,
					);
				} catch (error) {
					return new Response(`Error on cleanup: ${String(error)}`, {
						status: 500,
					});
				}
			},
		},
	},
});