42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import type { OfficialPositionResolverConfig } from "@/lib/jrDataSystemEnvironment";
|
|
|
|
export type OfficialPositionEditFrom = "eachTrainInfo" | "positions";
|
|
|
|
type OfficialPositionEditConfig = Pick<
|
|
OfficialPositionResolverConfig,
|
|
"officialPositionEditEnabled" | "officialPositionFrontendBaseUrl"
|
|
>;
|
|
|
|
/**
|
|
* Build the canonical UUID-based edit URL for the management Frontend.
|
|
*
|
|
* userID is intentionally a query parameter because the existing Frontend
|
|
* permission contract reads it before issuing admin API requests. The UUID
|
|
* remains in the path; position_id is never used as a query-only identity.
|
|
*/
|
|
export const buildOfficialPositionEditUrl = (
|
|
positionId: string | null | undefined,
|
|
userId: string | null | undefined,
|
|
config: OfficialPositionEditConfig,
|
|
from?: OfficialPositionEditFrom,
|
|
): string | undefined => {
|
|
if (!config.officialPositionEditEnabled) return undefined;
|
|
|
|
const normalizedPositionId = positionId?.trim();
|
|
const normalizedUserId = userId?.trim();
|
|
const baseUrl = config.officialPositionFrontendBaseUrl.trim().replace(/\/+$/, "");
|
|
if (!normalizedPositionId || !normalizedUserId || !baseUrl) return undefined;
|
|
|
|
const params = new URLSearchParams();
|
|
params.set("userID", normalizedUserId);
|
|
if (from === "eachTrainInfo") params.set("from", from);
|
|
|
|
return (
|
|
baseUrl +
|
|
"/train-positions/" +
|
|
encodeURIComponent(normalizedPositionId) +
|
|
"/edit?" +
|
|
params.toString()
|
|
);
|
|
};
|