import * as CANNED_RESPONSES from '../../../../utils/canned_responses.ts';
import { get_session, get_user, PRECHECK_TABLE, require_user } from '../../../../utils/prechecks.ts';

export const PRECHECKS: PRECHECK_TABLE = {};

// GET /api/users/me - Get the current user
PRECHECKS.GET = [get_session, get_user, require_user, (_req: Request, meta: Record<string, any>): Response | undefined => {
	const can_read_self = meta.user.permissions.includes('self.read');

	if (!can_read_self) {
		return CANNED_RESPONSES.permission_denied();
	}
}];
export function GET(_req: Request, meta: Record<string, any>): Response {
	return Response.json(meta.user, {
		status: 200
	});
}
