mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-05 20:56:13 -05:00
32 lines
973 B
TypeScript
32 lines
973 B
TypeScript
import type { LoaderFunctionArgs } from "react-router";
|
|
import { cors } from "remix-utils/cors";
|
|
import { z } from "zod/v4";
|
|
import { identifierToUserIdQuery } from "~/features/user-page/UserRepository.server";
|
|
import { notFoundIfFalsy, parseParams } from "~/utils/remix.server";
|
|
import { handleOptionsRequest } from "../api-public-utils.server";
|
|
import type { GetUserIdsResponse } from "../schema";
|
|
|
|
const paramsSchema = z.object({
|
|
identifier: z.string(),
|
|
});
|
|
|
|
export const loader = async ({ params, request }: LoaderFunctionArgs) => {
|
|
await handleOptionsRequest(request);
|
|
|
|
const { identifier } = parseParams({ params, schema: paramsSchema });
|
|
|
|
const user = notFoundIfFalsy(
|
|
await identifierToUserIdQuery(identifier)
|
|
.select(["User.discordId", "User.customUrl"])
|
|
.executeTakeFirst(),
|
|
);
|
|
|
|
const result: GetUserIdsResponse = {
|
|
id: user.id,
|
|
discordId: user.discordId,
|
|
customUrl: user.customUrl,
|
|
};
|
|
|
|
return await cors(request, Response.json(result));
|
|
};
|