Enhance operations configuration and UI; add new functions for schedule upload and duty filtering
This commit is contained in:
@@ -33,3 +33,18 @@ verify_jwt = false
|
||||
|
||||
[functions.operations-stop-alias-enhance]
|
||||
verify_jwt = false
|
||||
|
||||
[functions.operations-schedule-upload]
|
||||
verify_jwt = false
|
||||
|
||||
[functions.operations-schedule-meta]
|
||||
verify_jwt = false
|
||||
|
||||
[functions.operations-duty-detail]
|
||||
verify_jwt = false
|
||||
|
||||
[functions.operations-trip-detail]
|
||||
verify_jwt = false
|
||||
|
||||
[functions.operations-stop-detail]
|
||||
verify_jwt = false
|
||||
|
||||
@@ -43,6 +43,22 @@ function extractCode(rawStopName: string): string {
|
||||
return normalized.slice(0, 8);
|
||||
}
|
||||
|
||||
function hasStandaloneTerminusToken(rawStopName: string): boolean {
|
||||
const tokens = rawStopName
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.map((token) => token.toUpperCase())
|
||||
.filter((token) => token.length > 0);
|
||||
if (tokens.length === 0) return false;
|
||||
return tokens[tokens.length - 1] === "T";
|
||||
}
|
||||
|
||||
function applyStandRule(rawStopName: string, estimatedName: string): string {
|
||||
if (!hasStandaloneTerminusToken(rawStopName)) return estimatedName;
|
||||
if (estimatedName.toLowerCase().endsWith(" stand")) return estimatedName;
|
||||
return `${estimatedName} Stand`;
|
||||
}
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
const preflight = handleOptions(req);
|
||||
if (preflight) return preflight;
|
||||
@@ -143,13 +159,32 @@ Deno.serve(async (req) => {
|
||||
const estimated = codeToEstimated.get(code);
|
||||
if (!estimated) continue;
|
||||
for (const raw of rawStops) {
|
||||
const aliasWithStandRule = applyStandRule(raw, estimated);
|
||||
aliases.push({
|
||||
raw_stop_name: raw,
|
||||
alias_stop_name: estimated,
|
||||
alias_stop_name: aliasWithStandRule,
|
||||
source: "ai",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (aliases.length > 0) {
|
||||
const upsertRows = aliases.map((a) => ({
|
||||
channel_id: channelId,
|
||||
raw_stop_name: a.raw_stop_name,
|
||||
alias_stop_name: a.alias_stop_name,
|
||||
source: a.source,
|
||||
created_by: user.id,
|
||||
}));
|
||||
|
||||
const { error: upsertError } = await client
|
||||
.from("operations_stop_aliases")
|
||||
.upsert(upsertRows, { onConflict: "channel_id,raw_stop_name_normalized", ignoreDuplicates: false });
|
||||
|
||||
if (upsertError) {
|
||||
console.error("[operations-stop-alias-enhance] failed to persist aliases:", upsertError.message);
|
||||
}
|
||||
}
|
||||
|
||||
return json({ aliases });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user